“Engineering problems are under-defined; there are many solutions, good, bad, and indifferent. The art is to arrive at a good solution.”
All Patterns
17 patternsArrays & Strings
Fundamental data structure patterns for manipulating sequential data. Master these basics as they fo...
Backtracking
Build solutions incrementally, abandoning paths that cannot lead to valid solutions....
Binary Search
Divide search space in half each iteration. Works on sorted arrays or when searching for optimal val...
Dynamic Programming
DP = Recursion + Memoization (or Tabulation). Start by solving recursively, then optimize. The key i...
Greedy
Make the locally optimal choice at each step, hoping to find the global optimum. Unlike DP, greedy a...
Graphs
Network of nodes and edges. Key algorithms: DFS, BFS, topological sort, Union-Find, Dijkstra....
Hash Map / Set
Use hash tables for O(1) average lookups, frequency counting, and duplicate detection. Foundation fo...
Heap / Priority Queue
Efficiently track min/max elements. Essential for top K, streaming median, and scheduling....
Intervals
Problems involving ranges with start/end points. Key: sort by start or end time....
Linked List
Sequential data structure with node-based traversal. Key techniques: reversal, fast/slow pointers, d...
Prefix Sum
Precompute cumulative sums to answer range sum queries in O(1). Combined with HashMap for finding su...
Sliding Window
Maintain a window of elements that slides through the array. Track window state efficiently by addin...
Stack / Monotonic Stack
LIFO structure for matching pairs, expression evaluation, and finding next greater/smaller elements ...
Trees
Hierarchical data structure. Master DFS (preorder, inorder, postorder) and BFS (level order) travers...
Trie
Tree structure for efficient string prefix operations. Each node represents a character....
Two Pointers
Use two pointers to traverse data from different positions, often from both ends moving toward cente...
Union-Find
Track disjoint sets efficiently. Supports union (merge) and find (membership)....