13 topics, one page each. Every page opens with a step-through: the structure on one side, the code highlighting line by line on the other. Then the costs, the signals in a problem that call for it, and the mistakes people make with it.
Pick any topic below and press play. Everything on the coding track is free.
1def search(nums, target):2lo, hi = 0, len(nums) - 13while lo <= hi:4mid = lo + (hi - lo) // 25if nums[mid] == target:6return mid7if nums[mid] < target:8lo = mid + 19else:10hi = mid - 111return -11213def first_true(lo, hi, ok):14while lo < hi:15mid = lo + (hi - lo) // 216if ok(mid):17hi = mid # keep mid18else:19lo = mid + 120return lo
Eight sorted values and a target of 23. A linear scan costs up to eight comparisons. Sorted order buys something stronger: one comparison can rule out half the array at once.
Each topic builds on the ones before it. Colours group related ideas.
An array you index by content instead of position. The one structure that turns a nested loop into a single pass, and the one whose O(1) comes with conditions.
O(1)Lookup / insert / delete
Two indices walking the same array under a rule that lets each move retire part of the search. The technique that collapses a nested loop into one pass — when the data has an order to exploit.
O(n)Opposite ends (converge)
A contiguous span with two edges that only ever move forward. Turns "check every subarray" into one pass — as long as the window's validity is monotone.
O(n)Variable window (longest / shortest run)
Halve the candidate set on every comparison. Trivial to describe, easy to write wrong, and far more general than "find a value in a sorted array".
O(log n)Search a sorted array
Last in, first out — and the structure behind matching, undo, recursion, and the monotonic trick that answers "next greater" for every element in one pass.
O(1)Push / pop / peek
Nodes connected by references, with no index and no locality. Almost every question is pointer surgery: rewire the links without losing the rest of the list.
O(n)Access by position
Recursive structure, recursive solutions. Most tree questions are one traversal with the work moved to the right point in the recursion — and the cost is decided by the height, not the count.
O(n)Any traversal (DFS or BFS)
A tree stored in an array that keeps only one promise: the best element is at the front. Cheaper than sorting, and the right answer whenever a problem says top-k, median, or merge.
O(1)Peek the minimum
A tree keyed by characters, where the path spells the word. The structure that answers prefix questions a hash map cannot answer at all.
O(L)Insert / search a word
Nodes and edges, and two traversals that answer most questions about them. The hard part is usually recognising that a problem is a graph at all.
O(V + E)BFS / DFS (adjacency list)
Depth-first search over decisions, with the decision undone on the way back out. The answer to every "generate all…" and "find an arrangement that works" question.
O(2ⁿ · n)All subsets
Recursion that refuses to solve the same sub-problem twice. Exponential becomes polynomial the moment the repeated work is written down and reused.
O(n)1-D table (house robber, climbing stairs)
Ranges with a start and an end. Sort them the right way and almost every question becomes one linear pass — the difficulty is choosing which end to sort by.
O(n log n)Merge overlapping intervals