Pattern Recognition Guide
The single biggest difference between someone who’s “seen a lot of problems” and someone who’s actually fast at interviews and contests is pattern recognition — the ability to read a problem statement and, in seconds, know which of a couple dozen templates it’s really asking for. This page is a reference: a cue-to-pattern table you can scan top to bottom, and a decision tree for when the wording doesn’t immediately ring a bell.
What you’ll learn
- A single cue-to-pattern table covering the array/string/linked-list patterns from Phase 5, plus the graph and DP shapes from Phases 6 and 7.
- A decision tree for working from problem keywords to a pattern when nothing jumps out immediately.
- Where to go on this site to actually learn each pattern in depth.
The cue-to-pattern table
Read a problem statement, find the phrase closest to what it’s describing in the left column, and you have your starting point.
| Cue in the problem | Pattern | Learn it in |
|---|---|---|
| “sorted array, find a pair/triplet summing to X” | Two pointers | Two Pointers |
| “in place, no extra memory” on an array | Two pointers | Two Pointers |
| “longest/shortest contiguous subarray or substring” meeting a condition | Sliding window | Sliding Window |
| “linked list has a cycle” / “find the middle node” | Fast and slow pointers | Fast and Slow Pointers |
| “merge overlapping ranges/meetings/intervals” | Merge intervals | Merge Intervals |
| “array contains numbers from 1 to n” (find missing/duplicate) | Cyclic sort | Cyclic Sort |
| “reverse a linked list” (whole or in groups of k) | In-place reversal | In-place Linked List Reversal |
| “top / k largest / k closest / kth smallest” | Heap (top K) | Top K Elements |
| “merge k sorted lists/arrays” | K-way merge | K-way Merge |
| “generate all subsets/combinations/permutations” | Backtracking | Subsets and Combinations |
| “explore all valid arrangements subject to constraints” (N-Queens, Sudoku) | Backtracking | Backtracking |
| “next greater/smaller element”, “largest rectangle in histogram” | Monotonic stack | Monotonic Stack |
| “answer range sum queries fast”, “range update, then query” | Prefix sums / difference array | Prefix Sums and Difference Arrays |
| “minimize the maximum” / “maximize the minimum” feasible value | Binary search on answer | Binary Search on Answer |
| “fewest steps/moves in an unweighted graph or grid” | BFS | Breadth First Search |
| “does a path exist”, “explore every connected component” | DFS | Depth First Search |
| “number of ways to reach a target”, “optimal value given a sequence of choices” | Dynamic programming | Phase 6: Dynamic Programming |
| “shortest path with weighted edges” | Dijkstra’s algorithm | Phase 7: Graphs Advanced |
| “order tasks respecting dependencies” | Topological sort | Phase 7: Graphs Advanced |
| “are these two nodes connected”, “count connected components” incrementally | Union-Find | Phase 7: Graphs Advanced |
| “frequent range queries and updates on a large array” | Segment tree / Fenwick tree | Phase 8: Segment Trees and Lazy Propagation / Fenwick Tree |
A decision tree for picking a pattern
When no single phrase jumps out, work top-down through the shape of the input and the shape of the question being asked.
graph TD
N0{"What's the input shape?"}
N0 -- "sorted array + pair/triplet sum" --> N1["Two Pointers"]
N0 -- "subarray/substring + optimum or count" --> N2["Sliding Window"]
N0 -- "linked list: cycle or middle" --> N3["Fast and Slow Pointers"]
N0 -- "linked list: reverse a segment" --> N4["In-place Reversal"]
N0 -- "array of intervals/ranges" --> N5["Merge Intervals"]
N0 -- "array holds values 1..n" --> N6["Cyclic Sort"]
N0 -- "top/k/closest elements" --> N7["Top K Elements (Heap)"]
N0 -- "merge k sorted inputs" --> N8["K-way Merge"]
N0 -- "all subsets/permutations/valid arrangements" --> N9["Backtracking"]
N0 -- "next greater/smaller element" --> N10["Monotonic Stack"]
N0 -- "range sum, static array" --> N11["Prefix Sums"]
N0 -- "range sum or update, changing array" --> N12["Segment Tree / Fenwick Tree"]
N0 -- "minimize the max / maximize the min feasible value" --> N13["Binary Search on Answer"]
N0 -- "graph: fewest steps, unweighted" --> N14["Breadth First Search"]
N0 -- "graph: does a path exist, explore all" --> N15["Depth First Search"]
N0 -- "graph: cheapest path, weighted edges" --> N16["Dijkstra"]
N0 -- "count ways / optimal value with choices" --> N17["Dynamic Programming"]
How to use this guide
Don’t try to memorize the table — use it as a checklist while practicing. Read a problem, guess the pattern from memory first, then check this page to confirm. Being wrong and correcting yourself here is what builds the instant recall you want to have live in an interview or a contest, where there’s no lookup table to check.
🧪 Try It Yourself
Recap
- Match phrases in the problem statement to the cue-to-pattern table first — most problems are a direct hit or a close combination of two rows.
- When nothing jumps out, walk the decision tree from the shape of the input (array, linked list, graph, “choices”) down to a specific pattern.
- Watch for cues that look alike but diverge under extra constraints (negative numbers, non-monotonic windows) — confirm the invariant before committing.
- Every pattern named here has its own deep-dive page earlier in this site; this page is the index, not the tutorial.
Next: Contest Strategy — how constraints, time limits, and problem ordering change the way you apply these same patterns under contest pressure.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
