Home / Patterns / Lesson 0

How to Recognise Which Pattern a Problem Needs

Start Here โฑ 6 min read ๐Ÿงฉ Pattern 0 of 16

Strong candidates don't know more algorithms โ€” they recognise problems faster. Interview problems are variations of ~15 reusable patterns. Learn to spot the signal words, and half the battle is over before you write code.

The signal โ†’ pattern table

The problem says...                          โ†’  Reach for...
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
"sorted array" + find/search                 โ†’  Binary Search
"pair / triplet that sums to..."             โ†’  Two Pointers (sorted) or HashMap
"longest/shortest SUBSTRING or SUBARRAY"     โ†’  Sliding Window
"linked list" + cycle / middle               โ†’  Fast & Slow Pointers
"overlapping intervals / meetings"           โ†’  Merge Intervals
"top K / K largest / K most frequent"        โ†’  Heap (or sort if small)
"how many ways / min cost / max value"       โ†’  Dynamic Programming
"all combinations / permutations"            โ†’  Backtracking (DFS)
"shortest path / level by level"             โ†’  BFS
"valid parentheses / undo / nearest greater" โ†’  Stack
"range sum queries"                          โ†’  Prefix Sum
"count / frequency / seen before?"           โ†’  HashMap / Set

The 4-step routine for every problem

  1. Restate + clarify โ€” inputs, outputs, edge cases ("empty array? duplicates? negatives?").
  2. Say the brute force out loud โ€” "nested loops give O(nยฒ)". This scores points AND anchors your optimisation.
  3. Scan the signal table โ€” sorted? substring? K? intervals? Pick the pattern candidate.
  4. Apply the pattern template โ€” each lesson in this course gives you one to adapt.

How to use this course

Each lesson = one pattern: when to use it, the code template, a worked example, and problems on our DSA judge to solve immediately. Don't just read โ€” the pattern only sticks after you've used it twice. Start with Two Pointers.