Rolling Hit Counter

Asked at Affirm · Coding Questions · Difficulty: Medium · Last asked Oct 1, 2025

Build a counter that records timestamped events ("hits") on a service and reports how many of them happened during the most recent five minutes. This is the core of a request-rate dashboard: hits keep arriving, and at any moment you must say how many of them fall inside a sliding 300-second window.

Loading the problem…