Why it matters

Sliding window aggregation is core streaming op. Understanding shapes efficient stream.

Advertisement

The architecture

Deque of indices, monotonic increasing values.

Push new: pop tail while > new.

Pop head if out of window.

Sliding window minDequemonotonic indicesPush elementpop tail while >=Pop headif out of windowSame technique for sliding max, product, sum with careful design
Sliding window.
Advertisement

How it works end to end

Deque maintains monotonic values.

Head is current min.

Amortized O(1) per element.

Total O(n).