Phase 1 · Step 1 · Two Sum
Brute force tries 21 pairs. The trick needs 7 looks.
See the trick work, then solve it yourself.
Start with Two SumNew to coding? Start with the warm-up
18 phases · 57 visualizers · 63 problems · 16 quizzes
New to coding? Nested loops you can watch, ending on a walk through a list.
Two Sum, then the same question sorted, then one number in a sorted list: each clue changes the trick.
Linear and binary search: the two array-scanning fundamentals.
Coordinate two indices, or slide a window, to turn O(n²) array scans into O(n).
The three O(n²) sorts (bubble, selection and insertion), then the O(n log n) pair that splits the work: merge sort and quick sort.
LIFO and FIFO: the two simplest linear containers and the problem patterns they unlock.
Pointer manipulation, from walking the list to detecting cycles with Floyd's algorithm.
Constant-time lookup: hashing, collisions, and the two resolution strategies.
Recursion and hierarchical thinking: Tree DFS and BFS. Binary search trees get their own stage.
The complete-tree trick that keeps the min or max one step away, and powers priority queues.
The left-smaller / right-larger rule that makes a tree searchable, ordered, and the basis for balanced structures.
Vertices and edges, traversal by breadth and depth, and shortest paths with Dijkstra and Bellman-Ford.
Treat a grid as an implicit graph: BFS for shortest paths, DFS for flood fill and connected regions.
The choose, explore, un-choose template: N-Queens, Sudoku, Tower of Hanoi, and maze solving.
Turn exponential recursion into polynomial tables: Fibonacci, knapsack, coin change, LCS, and LIS.
Take the best local choice: activity selection, fractional knapsack, job sequencing, and Huffman coding.
Near-constant-time grouping with union by rank and path compression, for connectivity and cycle detection.
Prefix trees for O(length) string insert and search, the structure behind autocomplete and prefix matching.