Push, then release
transcript
Events arrive almost in sorted order. Each is at most k places off. A small heap can fix it. It needs only k plus one slots. But the order of steps matters.
Take six events, with k equal to one. The heap never holds more than two. The stream could be much longer.
Two and three wait in the heap. Then one arrives. Releasing first gives two. That is wrong. Push first, then release gives one. The right order is one, then two, then three.
The new event joins the heap first. Then release the smallest event in it. The heap holds k plus one events. No later event can be smaller.
Test k equal to zero. Test a single event. Test equal timestamps. Each one is a short test to write. Run all three tests before you submit.
Push the new event first. Then release the smallest. Full breakdown in the lecture.