While, not if
transcript
A deque tracks the shortest good run. The code drops starts from the front. One keyword decides if it is right. It is while, not if.
The changes are one and two. The target is two. At the end, the start before day one reaches the target. The start before day two reaches it too, with a shorter run.
An if drops only the oldest start. The shorter run is never measured, so the function returns two. A while drops both starts, and returns one.
One new prefix sum arrives at the back of the deque. Many old starts may reach the target together with it. Each of them must be measured and dropped.
A hundred thousand days took about two hundred thousand operations. That is two per prefix sum, so it stays linear.
Drop the front in a loop. Test two starts that both reach the target. Full breakdown in the lecture.