Minimum Size Subarray Sum: the skills you need first
Updated
LeetCode · medium · sliding window. Expand until the sum is enough, then shrink for the shortest cover.
Skills this problem builds on
Stuck on Minimum Size Subarray Sum? It is usually one of these. Get each one solid and the solution stops being a trick.
- Shrink to the smallest valid window
Once sum ≥ S, shrink while the window stays valid. Each successful exclude shortens a still-valid window. Stop when the next exclude would break S.
- Maintain the sum of the window
Window sum updates in O(1) per move: add a[R] when R advances, subtract a[L] when L advances. After every move, sum equals a[L]+…+a[R].
- Track the best valid bounds
When a valid window beats bestLen, save bestL and bestR (and the new length). The answer slice is a[bestL..bestR], not just a number.
check which ones you have 10 minutes, free, no account.