← Questions

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

0
OpenAICodingLast asked Sep 2026

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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding