AO
Back

Rate Limiter (Sliding Window)

Also reported as Sliding Window Rate Limiter · Per-Entity Rate Limiter

CodingOnsiteLast reported July 2026High Frequency

Problem Overview

A sliding-window rate limiter in two parts. It is the Roblox coding question our sources report most often, usually in the phone screen and sometimes in an onsite coding round. The platform shows the description and given signatures next to the editor and runs visible test cases plus hidden ones; you write the functions, not a main program.

Requests arrive as a list of timestamps sorted in increasing order (equal timestamps are allowed on this page). For each request, decide whether it is allowed (True) or denied (False), and return the list of decisions in request order. Only allowed requests are recorded; a denied request never counts against a later one.

Part 1 — Global sliding window

rate_limiter(requestTimestamps, windowLength, maxRequests, inclusiveStart=False) -> list[bool]: a request at time t is allowed when fewer than maxRequests allowed requests fall in the window (t - windowLength, t]. A request exactly windowLength earlier no longer counts.

Example: rate_limiter([1, 2, 3, 4, 5, 6], 3, 2) returns [True, True, False, True, True, False]. t=3 is denied (t=1 and t=2 are in the window); t=4 is allowed because t=1 has left the window and the denied t=3 was never recorded.

The prompt's notation writes the window as [t - windowLength, t], but its worked example leaves the left end out, and the two readings give different answers on that example. Ask which one is meant. The default here follows the example; inclusiveStart=True switches to [t - windowLength, t], where the same input gives [True, True, False, False, True, True]. The flag is our addition so the tests can show the difference.

Part 2 — Per user and per experience

per_entity_rate_limiter(requestTimestamps, userIds, experienceIds, windowLength, maxRequests) -> list[bool]: request i comes from user userIds[i] in experience experienceIds[i]. Every user and every experience has its own window, (t - windowLength, t], with the same maxRequests. A request is denied when either its user or its experience already has maxRequests allowed requests in the window; when allowed, it is recorded for both.

Example: per_entity_rate_limiter([1, 2, 3, 4, 5], [1, 1, 2, 1, 2], ["A", "A", "A", "A", "B"], 3, 1) returns [True, False, False, True, True]. t=2 is denied on the user (user 1 used its one request at t=1); t=3 is denied on the experience (A used its one request at t=1); t=5 is allowed, because the denied t=3 never used user 2's budget.

Follow-ups reported (not graded)

One report's follow-up was a request with several fields, each limited separately; another's was per-IP limiting. Both are the Part 2 structure with one map of queues per field.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Edge cases · 1Trade-off discussion · 4
Edge cases

Rate limit per IP address. (when: After Part 1 (one report))

Trade-off discussion

Now limit independently per user id AND per experience id. A request is denied if either limit is exceeded.

Probes for: After Part 1

What if a request has several fields, each of which needs its own limit? (when: After Part 1 (one report, as its second part))

What is the time and space complexity? (when: After Part 2 (one report))

How would you clean up keys that have gone idle, so the maps do not grow forever?

Probes for: Not confirmed for this question

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Sets or sorted containers per keyOne report says the follow-up solution added some sets. A sorted structure also handles unsorted timestamps, at O(log n) per operation; with sorted input a queue is simpler (our assessment).
Token bucket or fixed-window counterOur note: less memory, but they give different answers from the sliding-window examples in the prompt, so they do not pass this round's tests.

What Reports Emphasize

Common mistakes: One candidate had not worked out the condition for removing expired timestamps from the queue, got the wrong result and needed many hints.; Two candidates could not pass a hidden test on Part 2; one had passed the given tests and failed the round, the other suspected the platform's reference solution.; One candidate who failed said nerves made them spend too long on Part 1, leaving no time to fix a small bug later.; Our recommendation: in Part 2, check both queues before appending to either; appending to one first lets a request denied on the other axis use up budget.; Our recommendation: write only the given functions; on this platform a main program is not needed (one candidate lost time to that in a different Roblox round).

Interviewer hints: One candidate who had not thought through the expiry condition received many hints from the interviewer.; One interviewer pointed out a typo bug that the test cases had not caught.; One interviewer asked about complexity after Part 2.; The platform runs visible and hidden test cases; one candidate notes a failed hidden case is not shown.

What passers do: One candidate who moved forward used a deque for Part 1 and a dict of deques for the follow-up.; One candidate missed two hidden test cases and still passed the round; their view was that it depends on the interviewer.; One candidate who passed every test case was told afterwards by the interviewer that a typo bug had gone uncaught by the tests.

Practice

Write your own against 12 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Roblox with friends?

Send them this page. It is free to read, no account needed.

More Roblox Questions

Free preview

Every question in the Roblox catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 37 Roblox questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Roblox · Coding · Reported 23× across candidate reports
Is this helpful?