Grow right, shrink left
transcript
A rule decides how wide a window is. Testing every stretch is far too slow. Two edges, each moving only forward, are enough. The rule tells them when to move. Here is the loop.
The right edge advances once per step. The left edge advances only while the rule is broken. Neither edge ever moves back.
Count stretches with a product below one hundred. Ten joins. Add one. Five joins. The product is fifty. Add two. Two joins, and the product hits one hundred. Drop the ten. Add two. Six joins. The product is sixty. Add three. Eight in all.
Testing every stretch means five billion tests. The two edges make only two hundred thousand moves.
For the longest stretch, keep the maximum size. To count stretches, add the window size every step. If the window is empty, add zero.
Advance the right edge every step. Advance the left edge while broken. Full breakdown in the lecture.