Cheatsheet

The whole map on one page: which family a problem belongs to, and which signal points at which pattern.

7 families

Array Sweeps

You move indices along a line.

Binary Search

Sorted input, or an O(log n) requirement.

Linear Helpers

Process a sequence with one helper structure.

Heap

Keep only the important few.

Trees & Graphs

Traverse a structure.

Recursion Family

Explore possibilities or optimize.

Hashmap (sidekick)

Always-on tool to turn O(n^2) into O(n).

Signal → pattern (21)

Interview signals mapped to the pattern that solves them, grouped by family
If you see this signalReach for
Array Sweeps
Longest/shortest/max/min contiguous subarray or substringSliding Window
Grow right, shrink left while the window is invalid.
Sorted array, find a pair/triplet hitting a targetTwo Pointers
Converge left/right pointers.
Range sums, or subarray sum equals K (with negatives)Prefix Sum
Precompute cumulative sums; range = P[j]-P[i]; pair with a hashmap.
Values in 1..n; find duplicate/missing in O(1) spaceCyclic Sort / Index-as-Hash
The array is its own hash table.
Merge/insert overlapping intervals, meeting roomsIntervals
Sort by start, merge when curr.start <= prev.end.
Binary Search
Sorted array, find a boundary, or O(log n) requiredBinary Search
Find the monotonic yes/no predicate; while lo <= hi.
Search in a rotated sorted arrayRotated Binary Search
One half is always sorted; decide which to keep.
Linear Helpers
Matching/balance/nesting, undo lastStack
Push openers, pop and verify on closers.
Next greater/smaller, nearest larger to the rightMonotonic Stack
Keep an increasing/decreasing stack; each pop resolves an answer.
Linked list cycle/middle/nth-from-endFast & Slow Pointers
Two pointers at different speeds (tortoise and hare).
Heap
Top K / K largest / K closest / K most frequentHeap / Priority Queue
Keep a size-K heap; push/pop is O(log K).
Trees & Graphs
Level order, min depth, width per levelTree BFS
Process one whole level at a time with a queue.
Root-to-leaf path, subtree logic, validationTree DFS
Recurse; pass bounds/state down.
Islands/regions in a grid, shortest stepsGraph BFS/DFS
Flood-fill with a visited set; BFS for shortest.
Prerequisites, ordering, can-you-finish, dependenciesTopological Sort
Indegree + queue (Kahn); leftovers mean a cycle.
Connected groups, friend circles, merge accountsUnion-Find
Union elements, count distinct roots; path compression + rank.
Recursion Family
Generate all subsets/permutations/combinationsBacktracking
Choose, recurse, un-choose; prune early.
Number of ways / min cost / max value with overlapping choices1-D Dynamic Programming
Define state, transition, base case.
Two strings: edit distance, LCS, grid paths2-D Dynamic Programming
Grid of subproblems indexed by (i, j).
Palindromic substrings or longest palindromic subsequencePalindrome DP
Expand around each center, or fill a 2-D table.
Hashmap (sidekick)
Seen-before, count frequencies, group by key, deduplicateHashmap / Set
Trade space for O(1) lookups.