Sliding-Window Rate Limiter
250 points · 0 solved
Build the limiter that stops credential stuffing. The first line is n (1 ≤ n ≤ 4000). Each of the next n lines is t user — a timestamp in whole seconds (non-decreasing) and a user id.
A request at time t is allowed if that user has had fewer than 3 allowed requests with timestamp greater than t − 10. Denied requests don't count toward the limit. Print ALLOW or DENY for each request.
Example 1 input
6 1 alice 2 alice 3 alice 4 alice 11 alice 12 bob
Expected output
ALLOW ALLOW ALLOW DENY ALLOW ALLOW
main.py
Ctrl+Enter runs · Ctrl+Shift+Enter submits