AlgoScope

Maximum Sum Subarray of Size k

AlgorithmbeginnerSliding Window

Slide a fixed window across the array and keep the best sum it ever held.

Decision · step 2 of 7Sliding Window: Largest sum of 3 in a row
active 1-32011521334257617leftright

2 leaves and 1 enters, so the sum is 7. The best stays at 8.

Open in the player →or start at step 2

What you will see

The frame slides; the best window so far stays highlighted.

How sliding window works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

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.

Taught by the same lesson

Sliding Window covers these too, in the same run.