Event counter over a trailing 15-minute window with a ring buffer

0
Remix

Build an event counter for a monitoring system with two operations: record(timestamp) notes that an event happened at a given second, and count(now) returns how many events happened in the 15 minutes ending at now (later than now - 900, up to and including now).

Memory must stay fixed no matter how many events arrive, so use a ring buffer of per-second buckets. Handle many events in the same second, long gaps between calls, and stale buckets that must be cleared before reuse.

OpenAICodingLast asked Sep 2026
No answer yet. Write the first one; the best answer gets endorsed.