Sliding Window
Maintain a dynamic window over a contiguous subarray or substring to find optimal ranges in O(n) time.
- • Contiguous subarray/substring
- • Longest/shortest with constraint
- • Fixed-size window aggregation
- • Non-contiguous elements needed
- • Need to compare all possible subsets
- • Forgetting to shrink the window
- • Off-by-one on window boundaries
- • Not tracking window state correctly
Key Invariant
The window always satisfies the problem's constraint — expand right to explore, shrink left to restore validity