visual walkthrough
Minimum Size Subarray Sum
Shrinks while the window is valid, the mirror of the longest-window template.
The idea
Because every number is positive, adding to the window can only raise the sum and removing can only lower it. So grow the window until it is big enough, then shrink it from the left for as long as it stays big enough.
Each number is added once and removed once.
Complexity
| approach | time | space |
|---|---|---|
| Try every start | O(n²) | O(1) |
| Sliding window | O(n) | O(1) |