← Questions
Hit counter for the last five minutes
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Record hits (or events) as they arrive with a timestamp, and answer how many happened in the last five minutes (more generally, the last W seconds) at any moment. Discuss which structure to use and how old entries are dropped. Then improve memory: you do not need to keep every hit; bucket them by second in a fixed ring of counters.
Follow-up reported: many threads record and query at the same time, so make the counter thread-safe and say how you would keep the lock from limiting throughput.
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
