With all non-negative values, sliding window (two pointers) finds shortest subarray with sum in . Negative values break monotonicity of cumulative sums.
Expanding the window can decrease the sum. Prefix sums + monotonic queue handle this. We maintain increasing prefixes because larger prefixes are better left bounds. observation: if for , then is never a better left bound than for any future right bound.