RobloxOA #9
Implement a Rate Limiter
Estimated MediumJudge-ready
Topics (AI-labelled)IteratorsTwo Pointers
Rate-limit requests by key. The original problem allows fixed-window or sliding-window, requiring only consistency with the examples; this site explicitly uses a fixed window: the window number is floor(timestamp/window), and each key may have at most limit requests allowed within one window number. Rejected requests do not consume quota.
Input
The first line contains window limit q; then q lines of timestamp key. Added by this site: timestamp is a non-negative integer and non-decreasing, and key contains no spaces; 1≤q≤200000, 1≤window≤10^9, 1≤limit≤10^5.
Output
For each request, output ALLOW or REJECT, separated by spaces.
Example 1
Input:
10 2 6
1 alice
2 alice
3 alice
11 alice
12 alice
12 bob
Output:
ALLOW ALLOW REJECT ALLOW ALLOW ALLOW
Example 2
Input:
5 1 5
1 u
1 u
2 u
6 u
6 u
Output:
ALLOW REJECT REJECT ALLOW REJECT
Example 3
Input:
3 2 4
0 x
1 x
2 x
3 x
Output:
ALLOW ALLOW REJECT ALLOW
Editorial
Loading solution…