Pattern library · Tier B pillar

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.

Pattern

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.
Pattern

Two 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).
Pattern

Monotonic Stack

A stack whose elements stay in non-increasing or non-decreasing order.

Time O(n) amortized (each element is pushed and popped once).
Pattern

Prefix & Suffix

Precompute cumulative arrays so range queries answer in O(1).

Preprocess O(n); query O(1).
Pattern

Binary 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.
Pattern

Heap & 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).
Pattern

Union-Find (DSU)

A disjoint-set data structure supporting near-constant merge and find.

Amortized O(α(n)) per op with path compression + union by rank.
Pattern

Topological Sort

Linear ordering of a DAG consistent with its dependencies.

Time O(V + E); space O(V).
Pattern

Graph BFS / DFS

Breadth-first for shortest unweighted paths; depth-first for exhaustive traversal.

Time O(V + E); space O(V).
Pattern

Dynamic Programming

Break an overlapping-subproblem problem into a recurrence and cache results.

State × transition cost; typical O(n), O(n²), or O(n·m).
Pattern

Backtracking

DFS through a decision tree with pruning and state restoration.

Exponential in the decision depth; pruning is the whole game.
Pattern

Interval 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

  1. Run the free 10-minute diagnostic to find your weak patterns.
  2. Drill weak patterns first — one scenario variant per day.
  3. Move to company-specific pages to calibrate distribution.
  4. 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.