Skip to content

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 problemPatternLearn it in
“sorted array, find a pair/triplet summing to X”Two pointersTwo Pointers
“in place, no extra memory” on an arrayTwo pointersTwo Pointers
“longest/shortest contiguous subarray or substring” meeting a conditionSliding windowSliding Window
“linked list has a cycle” / “find the middle node”Fast and slow pointersFast and Slow Pointers
“merge overlapping ranges/meetings/intervals”Merge intervalsMerge Intervals
“array contains numbers from 1 to n” (find missing/duplicate)Cyclic sortCyclic Sort
“reverse a linked list” (whole or in groups of k)In-place reversalIn-place Linked List Reversal
“top / k largest / k closest / kth smallest”Heap (top K)Top K Elements
“merge k sorted lists/arrays”K-way mergeK-way Merge
“generate all subsets/combinations/permutations”BacktrackingSubsets and Combinations
“explore all valid arrangements subject to constraints” (N-Queens, Sudoku)BacktrackingBacktracking
“next greater/smaller element”, “largest rectangle in histogram”Monotonic stackMonotonic Stack
“answer range sum queries fast”, “range update, then query”Prefix sums / difference arrayPrefix Sums and Difference Arrays
“minimize the maximum” / “maximize the minimum” feasible valueBinary search on answerBinary Search on Answer
“fewest steps/moves in an unweighted graph or grid”BFSBreadth First Search
“does a path exist”, “explore every connected component”DFSDepth First Search
“number of ways to reach a target”, “optimal value given a sequence of choices”Dynamic programmingPhase 6: Dynamic Programming
“shortest path with weighted edges”Dijkstra’s algorithmPhase 7: Graphs Advanced
“order tasks respecting dependencies”Topological sortPhase 7: Graphs Advanced
“are these two nodes connected”, “count connected components” incrementallyUnion-FindPhase 7: Graphs Advanced
“frequent range queries and updates on a large array”Segment tree / Fenwick treePhase 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.

diagram Picking a pattern from problem keywords mermaid

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 coffee

Was this page helpful?

Let us know how we did