The sliding-window technique maintains a contiguous range (window) over an array or string and slides it instead of recomputing from scratch, solving many subarray/substring problems in O(n).
The idea
Expand the window by moving the right edge; shrink it by moving the left edge when a constraint is violated. Reuse the previous computation instead of rescanning.
Example: max sum of any window of size k
():
window = (arr[:k])
best = window
i (k, (arr)):
window += arr[i] - arr[i - k]
best = (best, window)
best
max_window_sum([, , , , , ], )
