Your question is API Rate Limiter Implementation. 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.
DoorDash Drive API requests must be limited independently for each client. Given a chronologically ordered stream of requests, determine whether each request should be accepted under a sliding-window rate limit.
A request is identified by its integer timestamp and client ID. A request is accepted when that client has made fewer than limit accepted requests during the current window seconds, including the current timestamp. Rejected requests do not consume quota.
Implement rate_limit(requests, limit, window), where requests is a list of two-element lists [timestamp, client_id]. Return a Boolean list whose element at index i indicates whether request i is accepted. Timestamps are nondecreasing, limit is positive, and window is a positive integer. A request at time t counts requests with timestamps in [t - window + 1, t].
def rate_limit(requests, limit, window):