The peak falls only when alone
transcript
A window slides, and a topic leaves it. That topic held the largest count. Two easy answers exist, and both are wrong. Does the peak fall?
If the peak never falls, it stays stuck at two. The heats are two, two, two, two. The total comes out as eight. The right heats are two, one, one, one. The right total is five.
If it always falls, it falls too early on some inputs. Topic one leaves, but topic two still holds two posts. So the peak stays at two. The right total is four.
The leaving topic must have held the peak count. No other topic may hold that same count. Only then does the peak fall by one.
Keep a table of how many topics hold each count. Read one entry of it when a topic leaves. Each check takes constant time, so the pass stays fast.
Never lowering the peak is wrong. Always lowering the peak is wrong too. Ask whether anyone else holds it. Full breakdown in the lecture.