arraystips
A sliding window needs a monotone condition
Anonymous
For a variable-size window that keeps a sum at most a limit, non-negative values make the boundary monotone: extend the right edge, then move the left edge until the sum is valid again. Each edge moves forward at most n times, so the scan is O(n). Negative values break that reasoning because removing one can increase the sum. What invariant do you check first when choosing a window?
0