← Questions
Event counter over a trailing 15-minute window with a ring buffer
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
