🎉 All 30 days are live — the full DSA-30 course, from Big-O to System Design. See the roadmap →
Day 30 - Victory LapThe Pattern Map

The Pattern Map

This is the page to re-read the morning of an interview. Almost every coding problem is a known pattern wearing a costume — and the meta-skill is stripping off the costume to see the shape underneath. Below: an interactive decision guide that maps problem clues to techniques (and back to the day that teaches them), then the Big-O reference table.

”If you see this, reach for that”

Filter by a keyword from the problem statement, or skim the whole list. Internalize these triggers and most mediums announce their own solution.

The decision guide — "if you see this, reach for that"
Filter by a keyword from the problem, or skim them all. Tap a row to reveal the technique.
If you see… Sorted array, find a pair / target+
If you see… Subarray / substring with a constraint+
If you see… "All permutations / combinations / subsets"+
If you see… "Max / min / count ways" + overlapping subproblems+
If you see… Top-k / k-th largest / streaming median+
If you see… "Have I seen this before?" / dedupe / frequency+
If you see… Shortest path in an unweighted graph+
If you see… Shortest path with weights+
If you see… Connected components / "are these joined?"+
If you see… Ordering with dependencies / prerequisites+
If you see… Prefix queries / autocomplete / word set+
If you see… Range sum/min/max on a mutable array+
If you see… "Next greater / smaller element"+
If you see… Matching parentheses / undo / DFS by hand+
If you see… "Maximize XOR" / bit-level constraints+
If you see… Search the ANSWER, not the array ("min capacity such that…")+
If you see… Linked list cycle / find middle+
If you see… Count inversions / "smaller after self"+
If you see… Greedy feels right (intervals, scheduling)+
If you see… "Design a system that scales to millions"+

The clue is almost always in the problem statement’s constraints and verbs, not its story. “Contiguous subarray” → sliding window. “All possible…” → backtracking. “Minimum number of… such that…” → often binary-search-on-the-answer or DP. “Already sorted” → two pointers or binary search. Train yourself to underline those phrases first — they’re the costume’s seams.

The complexity ladder

Know roughly what each complexity buys you at interview scale (n up to ~10⁵–10⁶ for most problems):

ComplexityNameFeels likeOK up to (~1s)
O(1)constantinstantany n
O(log n)logarithmicbinary searchastronomically large
O(n)linearone pass~10⁸
O(n log n)linearithmicsorting~10⁶–10⁷
O(n²)quadraticnested loops~10⁴
O(2ⁿ)exponentialall subsets~20–25
O(n!)factorialall permutations~10–12

The constraint tells you the target complexity. n ≤ 20? An exponential O(2ⁿ) is fine — think bitmask/backtracking. n ≤ 10⁵? You need O(n log n) or better — sorting or a hash map. n ≤ 10⁹? You can’t even read all of it — it’s O(log n) (binary search) or math. Reading the constraints backward into a target Big-O is one of the highest-leverage interview habits.

Data structure operations at a glance

StructureAccessSearchInsertDeleteNotes
ArrayO(1)O(n)O(n)O(n)contiguous, cache-friendly
Hash map / setO(1)*O(1)*O(1)**amortized; the universal speedup
Balanced BST / TreeMapO(log n)O(log n)O(log n)O(log n)keeps keys sorted
Heap (binary)O(1) peekO(n)O(log n)O(log n) poptop-k, priority
Stack / QueueO(1)O(1)LIFO / FIFO
TrieO(L)O(L)O(L)L = key length, prefix queries
Union-FindO(α(n))O(α(n))near-constant connectivity
Segment tree / BITO(log n)O(log n)O(log n)range query on mutable data

Algorithm complexity recap

AlgorithmTimeSpaceDay
Binary searchO(log n)O(1)13
Merge / Quick / Heap sortO(n log n)O(n) / O(log n) / O(1)11–12
BFS / DFSO(V + E)O(V)10
Dijkstra (heap)O((V + E) log V)O(V)21
Topological sortO(V + E)O(V)23
Most DP (1-D / 2-D)O(n) / O(n·m)same or reduced14
Sliding windowO(n)O(k)24
KMP / Z-algorithmO(n + m)O(m)27

The universal solve loop

When you’re stuck, run this — out loud, every time:

  1. Restate the problem and clarify the constraints. (What’s n? edge cases? what to return when there’s no answer?)
  2. Read the constraints into a target Big-O. (n ≤ 20 → exponential ok; n ≤ 10⁵ → need n log n.)
  3. Brute force first — get something correct, state its complexity.
  4. Find the repeated work — that’s where the optimization lives (hash it, sort it, two-pointer it, memoize it).
  5. Match it to a pattern from the map above.
  6. Code it, test it (incl. edges), state the final complexity.
⚠️

Don’t pattern-match so hard that you force the wrong tool. The map is a set of strong priors, not a lookup table — some problems are genuinely novel, and some combine two patterns (e.g. binary search on the answer with a greedy feasibility check). If a clue points somewhere but the details don’t fit, trust the details. The map gets you to a hypothesis fast; verifying it against the actual problem is still your job.

Quick check

A problem has n ≤ 22 and asks for the optimal assignment over all subsets. What does the tiny constraint signal?
The problem says 'find the longest contiguous subarray whose sum is at most k.' Which pattern does the phrasing point to?

Next: What’s Next — where to take these skills from here.