We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
When a problem looks new, the trick is rarely a new algorithm - it is recognising which of these shapes it maps onto. Each page below gives you the trigger condition to watch for in a problem statement, then every problem on gitGood that drills it.
30 patterns · read the patterns cheat sheet first
Hash maps and sets to trade memory for time - the most common first instinct in interviews.
Two indices walking a sorted array or string, usually from opposite ends.
A moving window over a contiguous run, expanding and contracting to hold an invariant.
Precomputed cumulative totals so any range query becomes one subtraction.
Halving a search space each step - on sorted arrays, and on answers themselves.
Last-in-first-out processing - matching, nesting, and deferred evaluation.
A stack kept sorted, for next-greater and largest-rectangle style questions.
Pointer manipulation - reversal, cycle detection, and merging without extra space.
Recursive traversal of binary trees and BSTs - depth, validation, and path problems.
A prefix tree for fast string lookup by shared prefix.
A priority queue for "top k" and streaming-median questions.
Level-by-level exploration with a queue - the shortest-path tool for unweighted graphs.
Depth-first exploration by recursion or explicit stack - connectivity and exhaustive walks.
Nodes and edges - traversal, connectivity, cycles, and shortest paths.
Disjoint-set structure for merging groups and answering connectivity fast.
Ordering a directed acyclic graph so every dependency comes first.
Systematic exploration of all candidates, abandoning partial ones that cannot work.
Overlapping subproblems solved once and reused - the pattern candidates fear most.
Take the locally best option each step and prove it stays globally optimal.
Sorting by start or end, then merging or scheduling overlapping ranges.
2D grid traversal, rotation, and in-place manipulation.
XOR, masks, and shifts - constant-space tricks for counting and pairing.
Number theory, digit manipulation, and closed-form reasoning.
Sorting as a preprocessing step - and the comparator that makes the problem easy.
Split the problem, solve the halves, and combine the results.
Parsing, comparison, and character-frequency reasoning.
Build a working data structure to an API - LRU caches, rate limiters, and iterators.
Coordinating threads with locks, semaphores, and condition variables.
Query-writing problems - joins, aggregation, window functions, and query tuning.
React and browser-platform problems - hooks, event handling, and rendering behaviour.