25 patterns · 115 tagged problems
Sorted by problem count, most common first
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.
Recursive or stack-based depth-first traversal; pre/in/post order.
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.
Two indices walk a sorted (or paired) structure from different positions to converge on a target.
Maintain a window of elements over a sequence; expand/shrink to satisfy a constraint while tracking an aggregate.
Two pointers move at different speeds through a linked structure to detect cycles or find midpoints.
Sort intervals by start, then sweep merging overlaps.
Binary search on a non-trivial space: rotated arrays, infinite arrays, the answer itself.
Explore a graph by levels (BFS) or branches (DFS), tracking visited nodes.
Reverse pointers segment by segment without extra space using prev/curr/next bookkeeping.
Make a locally optimal choice at each step; prove (or trust) it yields a global optimum.
DFS through a decision tree, undoing choices on failure to try alternatives.
Push items as they open and pop them as they finish, so the most recent unfinished item is always on top.
Place each number at its index by swapping; O(n) sort when values are a known bounded range like 1..n.
Level-order traversal using a queue; emit one level at a time.
Iteratively or recursively build all subsets/permutations/combinations by extending prior results.
Maintain a heap of size k to track the k largest/smallest/most-frequent elements.
Use a min-heap of k pointers (one per list) to merge k sorted sources in O(N log k).
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.
Tree where each edge is a character; O(L) insert/search/prefix.
Disjoint-set structure with path compression + union by rank for near-O(1) component queries.
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.
Use XOR's self-cancellation property to find unique elements or toggle bits efficiently.