← Sliding Window · guided lesson

Sliding Window

1 / 18 · story

the story

Fixed-size sliding window

Every tool here exists because something was too slow or broke without it. Here is what.

Running totals over the last k values are as old as moving averages in statistics; as an array technique it is programming folklore, and we found no single inventor to credit.

why it matters: without it

Every rolling average or "last k" check would re-scan its whole window: O(n·k) work, which turns into crores of operations on a single day of per-second data.

also in this chapter: Variable-size window (grow and shrink) · Monotonic deque (max / min of every window)