This question evaluates competency in designing per-client, time-windowed rate limiting using efficient data structures for time-based eviction and counting within the Coding & Algorithms domain.
You are extending the recent-requests counter to support per-client rate limiting.
Each request now includes a clientId identifying the caller. You must track hits separately for each client, still over the last 5 minutes.
Design and implement a class that supports the following operations:
void hit(String clientId, int timestamp)
clientId
at time
timestamp
(in seconds).
timestamp
.
int getHits(String clientId, int timestamp)
clientId
in the
past 5 minutes
, i.e., in the inclusive interval
[timestamp - 299, timestamp]
.
Additional requirements and constraints:
Define the class interface and implement the methods hit and getHits.