AlgoScope

Variable-Size Window

AlgorithmintermediateSliding Window

Grow the right end until a condition holds, then shrink the left end while it still does.

Decision · step 2 of 13Sliding Window: Shortest run summing to 7
active 0-0203112234435leftright

Grow right to index 0. 2 joins, so the sum is 2. Still short of 7.

Open in the player →or start at step 2

What you will see

The right edge advances; the left edge catches up only when needed.

How sliding window works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(k)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Cells announce index, value and whether they are inside the window; each step announces the window bounds and the running value.

Reduced motion: The window frame snaps to its new bounds with a crossfade.

Before this

Taught by the same lesson

Sliding Window covers these too, in the same run.