Algorithmic Patterns & Solving Techniques
Technical interviews test repeatable problem-solving techniques rather than memorized solutions. Explore the canonical taxonomy of algorithmic patterns, their core intuition, and vetted practice problems.
Arrays
3 patternsArray Rotation via Triple Reversal
Rotate an array in place by reversing the whole array and then reversing its two constituent segments.
Kadane's Algorithm
Track the best subarray sum ending at the current index, resetting to zero whenever the running sum turns negative.
Prefix Sum
Precompute running sums (or products) so range queries or comparisons become O(1) instead of re-scanning.
Backtracking
6 patternsBacktracking - Combinations
Build fixed- or variable-length combinations by choosing the next element from a remaining candidate pool.
Backtracking - Grid Path Search
DFS with backtracking over a 2D grid, marking/unmarking visited cells while searching for a path matching a target.
Backtracking - Partition/Cut Points
Build the recursion tree by choosing where to make the next cut/partition point, rather than an include/exclude decision per element.
Binary Search
3 patternsBinary Search (Classic Lookup)
Standard binary search over a sorted array (or a local monotonic comparison) to locate a target index or boundary.
Binary Search on a Rotated Array
Binary search adapted to a rotated sorted array by determining which half is still sorted at each step.
Binary Search on the Answer
Bit Manipulation
2 patternsDivide & Conquer
1 patternDynamic Programming
12 patterns0/1 Knapsack
DP where each item may be used at most once, choosing a subset that hits or approaches a target.
Circular Array DP
Handle a circular adjacency constraint by reducing to two linear DP passes that each exclude one end.
Expand Around Center
Treat every index (and gap between indices) as a palindrome center and expand outward while it still matches.
Graphs
10 patternsBFS Shortest Path (Unweighted)
Standard BFS where each edge has equal weight, so the first time a node is reached is guaranteed shortest.
Bounded-Hop Shortest Path (Bellman-Ford Style)
Relax edges for a limited number of rounds (bounding the number of hops/stops) rather than running unbounded Dijkstra, since the constraint makes plain Dijkstra unsound.
Dijkstra's Shortest Path
Priority-queue-driven shortest path on a weighted graph with non-negative edges, greedily finalizing the closest node.
Greedy
6 patternsBoyer-Moore Voting Algorithm
Maintain a single candidate and a counter, incrementing on a match and decrementing otherwise, to find a majority element in one pass with O(1) space.
Greedy Farthest-Reach Tracking
Greedily track the farthest index reachable so far while scanning left to right to decide feasibility or minimum jumps.
Greedy Interval Scheduling
Sort intervals by end time and greedily keep/skip each one to maximize non-overlapping selections.
Hashing
3 patternsHashmap Existence / Complement Lookup
Use a hashmap or set purely to answer 'have I seen this before' or 'does the complement exist', not to count occurrences.
Hashmap Frequency / State Counting
Track counts or per-key state (character tallies, bijective mappings) in a single pass with a hashmap, then compare or query those counts.
Heap
3 patternsHeap for Top-K / Kth Element
Maintain a fixed-size heap to track the k largest/smallest/most-frequent elements seen so far.
Quickselect
Use a partition step (like quicksort) to find the kth largest/smallest element in average O(n) without fully sorting.
Two Heaps (Median Maintenance)
Balance a max-heap of the lower half against a min-heap of the upper half to maintain a running median.
Intervals
1 patternLinked List
5 patternsFast/Slow Pointers (Cycle & Midpoint)
A tortoise-and-hare pair of pointers moving at different speeds to detect a cycle or find a midpoint/kth-from-end node.
Hashmap Node-to-Node Mapping
Use a hashmap as an old-object-to-new-object identity map to reconstruct a structure with internal cross-references (e.g. cloning a list with random pointers).
Linked List In-Place Reversal
Rewire next-pointers to reverse a linked list or a sublist in place without extra storage.
Math
4 patternsBig-Number Arithmetic Simulation
Simulate elementary-school arithmetic (add/multiply) digit-by-digit with carries, because the operands exceed native integer range.
Digit Manipulation Simulation
Peel off and reconstruct a number digit-by-digit to reverse it, check a property, or apply an increment.
Game Parity Reasoning
Matrix
1 patternSliding Window
2 patternsSliding Window (Fixed Size)
Slide a window of constant size across the input, incrementally updating window state as it moves.
Sliding Window (Variable Size)
Expand and shrink a window's right/left edges based on a validity condition to find an optimal-length substring/subarray.
Stack
4 patternsMonotonic Decreasing Stack
Maintain a stack that only ever decreases, popping elements when a larger one arrives to find next-greater relationships.
Monotonic Deque
Maintain a double-ended queue of candidate indices in monotonic order to answer sliding-window max/min in O(1) amortized.
Monotonic Increasing Stack
Maintain a stack that only ever increases, popping when a smaller element arrives to bound a region (e.g. largest rectangle).
Strings
2 patternsMulti-Pass String Construction
Build an output string through several structured passes or an explicit layout algorithm, rather than one linear scan.
String Index Scanning
A single linear pass over string indices (with simple lookups/comparisons) to extract or convert a value.
Trees
12 patternsBST Ordering Property
Exploit the left-less-than-node-less-than-right invariant of a BST to prune search space or produce sorted output.
Binary Indexed Tree (Fenwick Tree)
Use a BIT/Fenwick tree to answer prefix sum queries or range queries with point updates in O(log n) time, typically when the operation is associative and invertible.
Complete Tree Structural Binary Search
Tries
1 patternTwo Pointers
3 patternsSort Then Two Pointers
Sort the input first, then fix one element and use two pointers over the remainder to find combinations meeting a target.
Two Pointers (Opposite Ends)
Start pointers at both ends of a sorted or symmetric structure and move them toward each other based on a comparison.