Patterns
Most array problems are one of a handful of moves. Learn each move once and you will start to spot it everywhere. Each one has a live visualizer running the real code.
- 01Two pointersWalk in from both ends of a sorted array to find a pair with a given sum.O(n)
- 02Three-way partitionSplit an array into less than, equal to and greater than a pivot in one pass.O(n)
- 03Sliding windowSlide a window of k items, adding one and dropping one, instead of re-summing.O(n)
- 04Variable sliding windowGrow the window until it breaks a rule, then shrink it from the left.O(n)
- 05Prefix sumsKeep running totals so any subarray sum is a single subtraction.O(n)
- 06Monotonic stackKeep a stack in order to find every next greater value in one pass.O(n)