 All Problems
Design Hit Counter
medium
design
queue
binary search
dropbox
google
facebook

Design a hit counter which counts the number of hits received in the past 5 minutes (300 seconds).

  • void hit(int timestamp) — records a hit at given timestamp (in seconds).
  • int getHits(int timestamp) — returns the number of hits in the past 300 seconds.

Each function will be called with strictly increasing timestamp values.

Example:

hit(1), hit(2), hit(3), getHits(4)→3, hit(300), getHits(300)→4, getHits(301)→3
Run to check your code against the sample cases, or submit to run every case