Sliding window rate limiter

Write codeMedium25 minStripe style

Your task

Implement a per-IP sliding-window rate limiter. You are given a list of events [ip, timestamp] in non-decreasing timestamp order. Each IP may have at most limit accepted events within any window of window seconds (an event at time t counts events in the half-open interval (t-window, t]). Process events in order: return a list of booleans, True if the event is accepted (and thus counts toward the limit), False if it is rejected. Rejected events do not consume quota.

Examples

rate_limit(events: list[list], limit: int, window: int) -> list[bool]
Example 1
Inputrate_limit([["a", 1], ["a", 2], ["a", 3]], 2, 10)
Output[True, True, False]