Variable-Size 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
Grow right to index 0. 2 joins, so the sum is 2. Still short of 7.
What you will see
The right edge advances; the left edge catches up only when needed.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(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
Leads to
Topics that need this one first.
Taught by the same lesson
Sliding Window covers these too, in the same run.