How would you design a rate-limiting algorithm for an API gateway?
Implement a per-client sliding-window limiter that processes requests in nondecreasing timestamp order. Allow a request when fewer than limit previously allowed requests from that client occurred within the inclusive window [timestamp - window + 1, timestamp]; rejected requests do not consume capacity.
Use def rate_limit(requests, limit, window):, where requests is a list of [client_id, timestamp] pairs and the output is a Boolean list matching request order.
Example: [["a", 1], ["a", 2], ["a", 3]], limit = 2, window = 3 returns [true, true, false].
def rate_limit(requests, limit, window):