Coding interview prep
One page per concept. Each opens with a visualisation you can step through — the structure on top, the code running beside it — then the costs, the signals that call for it, and the mistakes that cost offers.
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.
OpenTwo 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.
OpenA 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.
OpenHalve 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".
OpenLast in, first out — and the structure behind matching, undo, recursion, and the monotonic trick that answers "next greater" for every element in one pass.
OpenNodes 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.
OpenRecursive 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.
OpenA 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.
OpenA tree keyed by characters, where the path spells the word. The structure that answers prefix questions a hash map cannot answer at all.
OpenNodes 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.
OpenDepth-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.
OpenRecursion that refuses to solve the same sub-problem twice. Exponential becomes polynomial the moment the repeated work is written down and reused.
OpenRanges 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.
Open