16 categories · 49 patterns · 90 techniques
Learn a pattern, then revise it.
Every pattern opens to a one-screen cheat sheet and practice sets: what's due, warm-up, interview level, hard and OA, and a lookalike test.
Topic guides
- Arrays & Two Pointers 5 patternsMost array questions are about not rescanning.
- Linked Lists 2 patternsLinked-list questions are pointer surgery.
- Binary Search 2 patternsBinary search halves a search space whose answer flips exactly once.
- Heaps & Priority Queues 3 patternsA heap hands you the best element so far in O(log n).
- Backtracking & Recursion 2 patternsBacktracking builds an answer one choice at a time and undoes each choice before trying the next.
- Trees 4 patternsTree problems are recursion with one question: what does each node return to its parent?
- Graphs 7 patternsModel the problem as nodes and edges first; the algorithm follows from what you're asked.
- Dynamic Programming 11 patternsDynamic programming is recursion that remembers: name the state, write the transition, fill the table.
- Stacks, Queues & Deques 2 patternsA monotonic stack keeps its elements in order by popping everything the new element beats, which answers "next greater" or "previous smaller" for every index in O(n).
- Strings & Tries 2 patternsStrings bring two patterns of their own.
- Advanced & Niche 4 patternsLower priority for most product-company interviews, higher for fintech, quant and competitive programming.
Signal → patternread the statement, match the signal: the quick table
| Sorted array; find a pair / triplet hitting a target, or shrink from both ends | Two Pointers |
| Contiguous subarray/substring asked to be longest/shortest/max/min under a constraint | Sliding Window |
| "Subarray sum equals k" / "divisible by k", or many range-sum queries | Prefix Sum + HashMap |
| A linked list that might have a cycle, or you need the middle in one pass | Fast & Slow Pointers |
| Reverse a list, a sublist, or every k nodes — O(1) extra space | In-place LL Reversal |
| Intervals / ranges that may overlap: merge, insert, or count rooms/conflicts | Merge Intervals |
| Array holds n numbers from a 1..n range; find missing / duplicate / first-missing-positive | Cyclic Sort |
| Many range increments, or count overlapping events at a point (bookings, car pool) | Difference Array / Sweep |
| Sorted or rotated-sorted array: find target, a boundary (first/last), or a peak | Binary Search |
| "Minimize the maximum" / "maximize the minimum", or answer is testable with a yes/no check | Binary Search on Answer |
| "k largest / smallest / most-frequent / closest", or "the kth …" | Top-K Heap |
| Median of a running stream; need max-of-low-half and min-of-high-half together | Two Heaps |
| k already-sorted lists/arrays to merge, or smallest range covering all k | K-way Merge |
| Generate ALL subsets / combinations / permutations | Subsets |
| Build a solution step by step and prune dead ends (board, word search, partition) | Backtracking |
| "Level order", level-by-level, right-side view, zigzag, or minimum depth | Tree BFS |
| Root-to-leaf paths, path sums, or a recursive subtree property (height, diameter) | Tree DFS |
| It says binary search tree; inorder is sorted; "kth smallest" / "validate" | BST Logic |
| Rebuild a tree from traversals, or serialize / deserialize it | Tree Construction |
| Grid/graph: islands, flood fill, connected regions, clone, unweighted shortest path | Graph BFS / DFS |
| Prerequisites / dependencies / build order on a DAG; "can you finish?" | Topological Sort |
| Connectivity / "number of components" / merge groups / redundant edge | Union-Find |
| Weighted shortest path, non-negative weights (min time/effort/cost) | Dijkstra |
| Shortest path with negative weights, or "cheapest within at most k stops" | Bellman-Ford |
| Shortest paths between ALL pairs of nodes (small graph) | Floyd-Warshall |
| Connect every node at minimum total cost | MST (Kruskal/Prim) |
| Count ways / max value where state depends on the previous one or two | DP · 1D / Fibonacci |
| Each item is take-or-skip under a capacity; subset hits a target; equal partition | DP · 0/1 Knapsack |
| Items reusable any number of times: coin change, perfect squares, rod cutting | DP · Unbounded Knapsack |
| Two strings/arrays compared: edit distance, longest common subsequence, align | DP · LCS family |
| Longest increasing / chain subsequence in one ordered array | DP · LIS |
| Longest palindromic sub-string/-sequence, or fewest palindrome cuts | DP · Palindrome |
| 2D grid, move right/down: count paths or min/max-cost path | DP · Grid |
| Solve a range [i..j] by trying every split point k (burst balloons, matrix chain) | DP · Interval |
| Buy/sell stock with states — cooldown, fees, or at-most-k transactions | DP · State Machine |
| Tiny n (≤ ~20) and you must "visit all" / assign everything | DP · Bitmask |
| Count how many numbers in [L, R] satisfy a digit constraint | DP · Digit |
| "Next/previous greater or smaller element", histogram area, trapping water | Monotonic Stack |
| Sliding-window maximum / minimum — running extremum over a window of size k | Monotonic Deque |
| Prefix matching, autocomplete/dictionary, word search on a grid, maximum XOR | Trie |
| Find a pattern inside a text efficiently, or detect repeated-substring structure | String Matching (KMP/Z) |
| "Single number", XOR tricks, counting set bits, powers of two, subset masks | Bit Manipulation |
| A locally-best choice provably gives the global best: scheduling, jumps, tasks | Greedy |
| "Design a class" with O(1) ops: LRU/LFU, min stack, insert-delete-getRandom | Design / DS combo |
| Primes (sieve), gcd/lcm, modular arithmetic, fast power, combinatorics | Math / Number Theory |
| Range query (sum/min/max) WITH updates, or count smaller elements to the right | Segment Tree / Fenwick |
| Pick a random element from a stream of unknown length, one pass | Reservoir Sampling |