27 patterns · 178 tagged problems
Sorted by problem count, most common first
Define a state over positions, prefixes or pairs of prefixes, build each state from a few smaller ones, and fill the table in dependency order.
Recursive or stack-based depth-first traversal; pre/in/post order.
Explore a graph by levels (BFS) or branches (DFS), tracking visited nodes.
Trade memory for speed: a hash map or set answers 'have I seen this?' in O(1), so one pass can count, group, or match what nested loops would compare pair by pair.
Maintain a window of elements over a sequence; expand/shrink to satisfy a constraint while tracking an aggregate.
Two indices walk a sorted (or paired) structure from different positions to converge on a target.
Binary search on a non-trivial space: rotated arrays, infinite arrays, the answer itself.
Make a locally optimal choice at each step; prove (or trust) it yields a global optimum.
Work from the structure of numbers and coordinates: index formulas for matrices, digit arithmetic with carries and overflow checks, repeated squaring for powers, and coordinate lookups for shapes.
Push items as they open and pop them as they finish, so the most recent unfinished item is always on top.
Sort intervals by start, then sweep merging overlaps.
Level-order traversal using a queue; emit one level at a time.
Use XOR's self-cancellation property to find unique elements or toggle bits efficiently.
DFS through a decision tree, undoing choices on failure to try alternatives.
Maintain a heap of size k to track the k largest/smallest/most-frequent elements.
Walk and rewire node pointers directly, with a dummy head in front so changes at the start of the list need no special case.
Two pointers move at different speeds through a linked structure to detect cycles or find midpoints.
Reverse pointers segment by segment without extra space using prev/curr/next bookkeeping.
Iteratively or recursively build all subsets/permutations/combinations by extending prior results.
Choose/skip decisions over items with capacity; tabulate optimal value for subproblems.
Order a DAG so every edge points forward; Kahn's BFS using in-degrees, or DFS post-order.
Disjoint-set structure with path compression + union by rank for near-O(1) component queries.
Place each number at its index by swapping; O(n) sort when values are a known bounded range like 1..n.
Use a min-heap of k pointers (one per list) to merge k sorted sources in O(N log k).
Tree where each edge is a character; O(L) insert/search/prefix.
Stack/deque maintained in increasing or decreasing order to answer next-greater/smaller queries.
Maintain a max-heap for the lower half and a min-heap for the upper half of a stream.