You are designing an in-memory component for a web service that needs to track how many requests ("hits") it has received in the last 5 minutes.
Implement a class that supports two operations:
void hit(int timestamp)
timestamp
(in seconds).
timestamp
.
int getHits(int timestamp)
[timestamp - 299, timestamp]
), where
timestamp
is also specified in seconds and is >= any previous timestamp seen.
Additional details and constraints:
hit
and
getHits
per second.
Define the class interface and implement the methods hit and getHits.