Keep a summary
transcript
A window holds counts of topics. You need the largest count each step. Rescanning the table every step is slow. Keep the answer beside the counts.
Rescanning costs almost a hundred million steps. A kept summary costs a hundred thousand.
The first window has two ones. The peak is two. A one leaves, and nobody else holds two. The peak falls to one. A one joins again. Its count reaches two. The peak is two. Two, one, two. The total is five.
Keep a table of how many topics hold each count. When a topic leaves at the peak, check the table. The peak falls only if nobody else holds it.
Sometimes the width comes from the data. To group ready bins, the window is as wide as their count. Swaps are the width minus the best window.
Name the one number the answer reads. Keep it beside the counts. Full breakdown in the lecture.