Coding exercise on a rolling window
Failed playback attempts arrive in timestamp order. For each new failure at time t, report how many failures occurred in the previous 10 seconds, including the new event and excluding events at exactly t minus 10. Explain how you’ll handle two failures with the same timestamp.
Keep timestamps in a queue. Add the new event, remove entries at or before the cutoff, then return the queue length. Each event enters and leaves the queue at most once, so the work is amortized constant time per event and the space depends on the number of events inside the window.
For a follow-up, allow events to arrive out of order. First agree on whether results can be delayed or corrected. If a small delay is acceptable, a bounded buffer can reorder events within the agreed lateness. Define what happens to events that arrive after that limit.
Capture the written prompt in a Hiintly Coding Interview session after solving it. Ask for a walkthrough with a duplicate timestamp and an event at the cutoff, then use the coding interview copilot guide to compare the explanation with your own tests.