Coding Interview Patterns: The 18 That Cover Almost Everything
-
Jason Yang - 05 Aug, 2026
- Views —
Most interview problems aren’t original. Strip the backstory off a few hundred of them and you’re left with maybe eighteen recurring shapes — a sliding window here, a monotonic stack there, a recurrence you’ve seen before wearing new variable names. The thing that separates people who grind 500 problems from people who pass having done 150 isn’t volume; it’s recognizing which pattern a new problem is dressed up as.
This page is the map. Each entry below links to a full walkthrough of one pattern — the Java template, why it works, and the Blind 75 and NeetCode 150 problems it unlocks. Read the pattern first, then the individual solutions hang off it. If you only have time for one habit, make it this: before writing any code, name the pattern out loud.
Arrays, strings, and the linear-scan toolkit
The first four cover the bulk of “easy” and “medium” array and string problems — the trick is almost always replacing a nested loop with a smarter single pass.
- Arrays and Hashing — reach for a hash map the moment a nested loop is really asking “have I seen this before?”. It trades memory for lookups and turns scans linear.
- Two Pointers — on a sorted array or a string, two indices moving toward (or alongside) each other collapse a brute-force pair search into one pass.
- Sliding Window — when the answer is the best contiguous run under some constraint, grow and shrink one window instead of re-scanning every subarray.
- Stacks — when the current element can only be resolved by something you saw earlier: matching brackets, evaluating expressions, or a monotonic stack that finds the next-greater element in one pass.
Searching a space, not just an array
- Binary Search — far more than a sorted-array lookup. The boundary template also lets you search on the answer (the smallest feasible capacity, the minimum viable value) and untangles rotated arrays.
Linked structures
- Linked Lists — three moves cover most of them: a dummy head to kill edge cases, fast-and-slow pointers for cycles and midpoints, and in-place reversal.
Trees, tries, and heaps
- Binary Trees — nearly always recursion plus the right traversal. Decide what each call returns and whether you need pre-, in-, or post-order DFS or a level-by-level BFS.
- Tries — when prefix itself is the query: autocomplete, wildcard search, or pruning a grid word search before it explodes.
- Heaps / Priority Queues — when you only need the extreme, not a full sort. A size-
kheap gives top-k; two heaps give a running median.
Recursion trees and graphs
- Backtracking — a decision-tree DFS with an undo step. The choose / explore / unchoose template covers permutations, combinations, subsets, and constraint puzzles.
- Graphs — most graph problems are disguised as grids, prerequisites, or connectivity questions. Once you spot the nodes and edges, it’s BFS or DFS with a visited set.
- Advanced Graphs — when edges carry weights or you need an ordering: Dijkstra, topological sort, union-find, and minimum spanning trees.
Dynamic programming
- 1D Dynamic Programming — name the state, find the recurrence. Climbing Stairs, House Robber, and Coin Change are all the same “build the answer from smaller answers” move.
- 2D Dynamic Programming — when the state needs two indices — two strings, a grid, or an extra mode — and each cell reads from its neighbors.
Greedy, intervals, math, and bits
- Greedy — fast to write and often wrong. The exchange argument is how you prove the locally best choice is also globally optimal before you trust it.
- Intervals — sort first, then sweep once: merge overlaps, insert into a sorted set, or count concurrent meetings for a room count.
- Math and Geometry — in-place matrix manipulation with careful index arithmetic, plus simulating arithmetic that would otherwise overflow.
- Bit Manipulation — a handful of identities carry a whole cluster: XOR cancels pairs,
n & (n - 1)strips the lowest set bit, and shifts multiply without a*.
How to actually use this
Working through the patterns beats working through a problem list. Pick one hub, read why the template works, then do its problems back to back until the shape is automatic — you’ll start seeing “this is just a sliding window” on problems that never mention windows. That recognition, not memorized code, is what the interview is testing.
Each hub links to the individual Blind 75 and NeetCode 150 solutions it covers, so you can drill a pattern end to end. Start wherever your next interview is weakest.