The 12 patterns that cover ~90% of coding interviews.
Every coding-interview problem reduces to one of 12 algorithmic patterns. Learn the shape once, and the next 20 problems stop looking like new problems.
Sliding Window
Maintain a contiguous range and slide its boundaries to avoid recomputation.
Time O(n), space O(1) or O(k) for a frequency map.PatternTwo Pointers
Two cursors moving independently over a sorted or monotone structure.
Time O(n) after an optional O(n log n) sort; space O(1).PatternMonotonic Stack
A stack whose elements stay in non-increasing or non-decreasing order.
Time O(n) amortized (each element is pushed and popped once).PatternPrefix & Suffix
Precompute cumulative arrays so range queries answer in O(1).
Preprocess O(n); query O(1).PatternBinary Search on Answer
When a predicate is monotonic over the answer space, binary search the answer itself.
Time O(log R · feasibility(n)) where R is the answer range.PatternHeap & Priority Queue
A data structure that returns the min or max in O(log n) per operation.
Insert/pop O(log n); peek O(1); heapify O(n).PatternUnion-Find (DSU)
A disjoint-set data structure supporting near-constant merge and find.
Amortized O(α(n)) per op with path compression + union by rank.PatternTopological Sort
Linear ordering of a DAG consistent with its dependencies.
Time O(V + E); space O(V).PatternGraph BFS / DFS
Breadth-first for shortest unweighted paths; depth-first for exhaustive traversal.
Time O(V + E); space O(V).PatternDynamic Programming
Break an overlapping-subproblem problem into a recurrence and cache results.
State × transition cost; typical O(n), O(n²), or O(n·m).PatternBacktracking
DFS through a decision tree with pruning and state restoration.
Exponential in the decision depth; pruning is the whole game.PatternInterval Sweep
Sort events by time, sweep a line, maintain an active set for overlap questions.
Time O(n log n) for the sort; O(n) for the sweep.How to use this library
- Run the free 10-minute diagnostic to find your weak patterns.
- Drill weak patterns first — one scenario variant per day.
- Move to company-specific pages to calibrate distribution.
- Book peer or AI mocks to practice explaining under a clock.
Frequently asked questions
- What are the 12 coding interview patterns?
- Sliding window, two pointers, monotonic stack, prefix and suffix, binary search on answer, heap and priority queue, union-find, topological sort, graph BFS/DFS, dynamic programming, backtracking, and interval sweep. Together they cover roughly 90% of technical interview problems.
- Are coding interview patterns enough to pass FAANG interviews?
- Patterns get you to competent — 80% of the loop. The last 20% is translation speed and edge-case recognition, which comes from drilling pattern variants under a clock. The 12-pattern library is necessary but not sufficient.
- How long does it take to learn all 12 patterns?
- A dedicated learner can internalize the mental models in 3–4 weeks and develop fluent pattern recognition in 8–12 weeks. Most candidates underestimate the reps required for the last step.
- What's the difference between patterns and problems?
- A problem is a specific puzzle ("find all pairs summing to k"). A pattern is the shape that solves 20 similar problems (two pointers on a sorted array). Learning patterns transfers; memorizing problems doesn't.
- Is this the same as Grokking the Coding Interview?
- Overlapping concept taxonomy — the 12-pattern framework is widely used in the industry. Alpha Code's library is original content: our own scenario variants, walkthroughs, and animations.
Run the free diagnostic.
Ten-minute patterns quiz. No card. Personalized loop starts on the other side.