Minutes, not windows
transcript
Demand is five, five, five, zero. A window is two minutes. It needs ten requests. How many minutes surge?
Two windows reach ten. Together they cover three minutes. Adding two per window gives four.
Minute one is in both windows. Adding k counts it twice. The answer is three.
Here is the demand: five, five, five, zero. The first window covers minutes zero and one. The second covers minutes one and two. Minute three is quiet, so it never surges.
Keep a mark. It is the first minute not yet counted. Add only the new minutes.
Test overlapping windows. Test a total equal to the threshold. Test a day with no surge.
A day has many minutes. Many windows overlap each other. One running total handles them all.
Surge prices are paid per minute. A double count overcharges. Count each minute once.
Mark what you have counted. Full breakdown in the lecture.