Your question is API Rate Limiter Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Oracle Health APIs need a rate limiter that enforces both a per-client quota and a per-route quota. Process requests in arrival order and accept a request only when adding it would keep both quotas within their limits.
Use an exact sliding window. For a request at timestamp t, only previously accepted requests with timestamps greater than t - window count. Rejected requests do not consume quota.
Implement rate_limit(requests, client_limit, route_limit, window). requests is a list of records, where each record is [client_id, route, timestamp]. client_id and route are strings, and timestamp is an integer. Return a list of booleans in the same order, where True means accepted and False means rejected.
Timestamps are nondecreasing across the input. The client quota counts accepted requests from that client across all routes. The route quota counts accepted requests to that route across all clients.
def rate_limit(requests, client_limit, route_limit, window):