Coding interviews recycle a shockingly small set of ideas. Behind thousands of "novel" problems live maybe fifteen patterns; recognizing which one a problem wants is most of the battle. This cheat sheet covers the highest-yield patterns with their recognition cues — the signals in a problem statement that should trigger each tool. Pair it with the 12-week plan and complexity fundamentals.
1. Two pointers#
Cue: sorted array (or sortable), pairs/triplets with a target property, "in-place" manipulation.
Opposite-end pointers converge inward; same-direction pointers chase each other. Classic forms: pair-sum in sorted input, removing duplicates in place, palindrome checks. The magic is always the same — each pointer move discards a provably-useless region, collapsing O(n²) to O(n).
2. Sliding window#
Cue: contiguous subarray/substring with "longest," "shortest," or "at most K" constraints.
Maintain a window [left..right] whose state (sum, char counts) updates incrementally as it slides. Expanding right explores; contracting left restores validity. The pattern converts every brute-force recount of O(n) windows into amortized O(n). Recognition cue worth drilling: any problem where re-computing the window's state from scratch would be redundant work.
3. Binary search (and on the answer)#
Cue: sorted data — or a monotonic yes/no predicate ("is speed X enough to finish by deadline?").
Classic search is table stakes. The advanced move interviewers love: binary searching the answer space when feasibility is monotonic ("minimum capacity to ship within D days"). If you can write feasible(mid) as a cheap check, you can binary-search values that were never stored anywhere.
4. Hash map for O(1) lookups#
Cue: "have I seen this before?", counting frequencies, complement lookups (two-sum family), grouping by computed key.
The humble workhorse of interviews (when to reach for which structure): trading memory for time. Group-anagram problems are frequency-counting in disguise; cycle detection via visited-sets is hash-map membership in disguise.
5. BFS / DFS on graphs and grids#
Cue: grids, adjacency, "minimum steps," "connected components," "all paths."
- BFS = shortest path in unweighted graphs (level-by-level expansion)
- DFS = exhaustive exploration, backtracking, cycle detection
- Grid problems are graph problems wearing costumes — each cell is a node, neighbors are moves
Template discipline wins here: visited-set management, queue vs stack choice, and level tracking are where bugs live, not in cleverness.
6. Backtracking#
Cue: "generate all…" — permutations, subsets, combinations, N-queens, sudoku.
Recursive choose → explore → unchoose. The entire pattern is one function shape plus pruning rules; memorize the skeleton once and every combinatorial problem becomes configuration. Complexity is inherently exponential — saying so out loud earns points.
7. Dynamic programming#
Cue: overlapping subproblems + optimal substructure; counts, minimums/maximums, "how many ways."
Start top-down with memoization (it mirrors the recursive definition), convert bottom-up only if natural. The real skill is defining dp[i] precisely in words before writing code — "dp[i] = longest increasing subsequence ending at index i." Vague states produce broken transitions; precise states make code write itself. Learn the classics (climbing stairs, house robber, coin change, LCS) deeply enough to modify, since interviews mutate them.
8. Heap / priority queue#
Cue: "top K," "K closest," "merge K sorted," streaming median, scheduling by priority.
Whenever full sorting is overkill because you only care about extremes, a heap does it in O(n log k). The merge-K-lists pattern (heap of current heads) and two-heap median trick are the two configurations worth knowing cold.
9. Intervals#
Cue: calendar/meeting problems, ranges, "minimum rooms/platforms."
Sort by start, then sweep: overlap detection is pairwise comparison against the active interval; "minimum rooms" is the classic transform into "maximum simultaneous overlaps" (sort starts and ends separately, count concurrency). Cheap pattern, frequent appearance.
10. Monotonic stack#
Cue: "next greater element," spans, histogram areas, temperature waits.
A stack keeping elements in sorted order while sweeping: pop everything smaller when a bigger element arrives — each popped element just found its answer. Looks obscure until learned; then appears constantly.
How to actually use this list#
For each pattern: learn its cue → solve three canonical problems → solve two mutations (interviews never ask the canonical version). Then re-solve from scratch after 3+ days (the review loop). Mastery target: hearing a problem and thinking "this smells like monotonic stack" within sixty seconds. That reflex — not raw IQ — is what experienced candidates are selling.
Related: data structure selection · live-coding delivery · system design framework