Patterns

Pattern recognition (when stuck, what to try)

Skim the Signal column to find your situation, reach for the named Technique, then open that section on the Techniques page for the how-to. "Practiced" lists LC problems in problem_log.md that exercised it.

SignalTechniquePracticed
Sorted array → find pair/triplet/k-sumTwo pointers (or binary search)
Search a sorted/monotonic spaceBinary searchLC 374
Count elements ≥ threshold in sorted array; "leftmost match"Binary search / bisect_leftLC 2300
Peak / local max in unsorted array, O(log n)Binary search on slopeLC 162
Min/max value such that a condition holds (capacity, speed)Binary search on the answerLC 875
Unsorted → find pair summing to KHashing (map of complements)
Substring/subarray with a constraintSliding windowLC 643, 1456, 1004, 1493
Top-k / kth smallest or largestHeap of size kLC 215
Min/max extraction + custom ops over a huge/infinite domainHeap + set + frontier counterLC 2336
Score = sum(k from A) × extremum(k from B)Heap (sort by B, size-k on A)LC 2542
Pick k from either end, cheapestHeap (two heaps + two pointers)LC 2462
Median of a streamHeap (two heaps, max+min)
Linear recurrence f(n) from last k valuesDynamic programmingLC 1137, 746
Pick-or-skip with a per-step constraint (no-adjacent, cooldown)Dynamic programmingLC 198
Count / weight paths in a gridDynamic programming (2D)LC 62
Compare / align / edit two sequencesDynamic programming (2D)LC 1143, 72
Tiling / complete-vs-jagged boundaryDynamic programming (state-augmented)LC 790
Sequential decision with state-dependent actionsDynamic programming (state-augmented)LC 714
"How many ways to…" / count pathsDynamic programming (count)
Min/max steps to reach a stateBFS (unweighted) / Dijkstra / DP
Reachability / connected-component traversalGraph DFS/BFSLC 841, 399
Weighted-edge path value composes along edgesGraph DFS (carry value in the tuple)LC 399
Count connected componentsGraph DFS/BFS seeds, or Union-FindLC 547
Incremental connectivity / equivalence classesUnion-FindLC 547
Cycle / connectivity / dependency orderingUnion-Find / DFS colors / topo sort
All permutations / combinations / subsetsBacktrackingLC 17, 216
Combinations (order-free, no duplicates)Backtracking (start index)LC 216
Merge / overlap intervalsIntervals (sort by start, sweep)
Remove fewest / min arrows to stab intervalsIntervals (greedy, sort by end)LC 435, 452
Locally-optimal choice each stepGreedy (prove via exchange argument)LC 605, 334
Palindrome / reverse-in-place / optimal pairTwo pointers (from ends)LC 345, 11
Remove / compact / overwrite in placeTwo pointers (same direction)LC 443, 283
Match / merge two parallel sequencesTwo pointers (one per sequence)LC 392
Midpoint / nth-from-end / cycle in linked listTwo pointers (slow/fast)LC 2095, 2130
Reverse a linked list / sub-chainLinked-list 3-pointer reverseLC 206, 2130
"Cancel / match most recent" (parens, undo)StackLC 2390
Next-greater / next-smaller elementMonotonic stackLC 739
Streaming span / count of prior ≤ currentMonotonic stackLC 901
Frequency / anagram / repeating charsHashing (Counter / dict)LC 1207, 1657
Set difference / membership across collectionsHashing (set ops)LC 2215
Match identical sequences across collectionsHashing (hash a tuple)LC 2352
Divide into self-similar piecesRecursion / divide & conquerLC 1071
Range sum / range update queriesPrefix sum (or Fenwick tree)LC 238
Repeated prefix matches in a set of wordsTrieLC 208
Top-k lex-smallest words per prefix (autocomplete)Trie + bounded DFSLC 1268
LRU / fixed-capacity cacheOrderedDict, or dict + DLL (see Data Structures)
Sliding time window over eventsSliding window (deque)LC 933
Tree traversal (pre/in/post, depth, leaves)Trees (DFS)LC 104, 872
Tree DFS carrying state down the pathTrees (DFS + param)LC 1448
Path-sum / ancestor-window on a treeTrees (DFS + backtracking path)LC 437
Tree answer derivable bottom-upTrees (bottom-up DFS)LC 1372, 236
LCA / lowest node satisfying PTrees (DFS return found-node up)LC 236
Tree level-order / first-or-last per levelTrees (BFS)LC 199
Tree per-level aggregateTrees (BFS level snapshot)LC 1161
Shortest path on unweighted graph/gridBFSLC 1926
Search / insert / delete in a BSTTrees (BST walk)LC 700
Mutate a tree (delete / insert / trim)Trees (recurse, return new subtree root)LC 450
Popcount for every number in 0..nBit manipulation (bit DP)LC 338
Every element appears twice except oneBit manipulation (XOR fold)LC 136
Bit-by-bit decision across operandsBit manipulation (casework)LC 2275