Meta wants to protect an internal API endpoint used by systems like TAO-backed services from bursts of traffic. Implement a per-user sliding window rate limiter that decides whether each request should be allowed.
Given a list of request events sorted by non-decreasing timestamp, determine for each event whether it is accepted under the rule: a user may make at most limit requests in any rolling interval of window_size seconds, inclusive of the current timestamp.
Implement a function:
requests: List[List[int]], where each element is [timestamp, user_id]limit: intwindow_size: intList[bool], where result[i] is True if requests[i] is allowed, otherwise FalseA request at time t counts all previously accepted requests for the same user with timestamp >= t - window_size + 1 and <= t.
def rate_limiter(requests, limit, window_size):