FastPrepRate Limiter Sliding Window With Per-Entity Limits
Problems/Rate Limiter Sliding Window With Per-Entity Limits

Rate Limiter Sliding Window With Per-Entity Limits

Roblox logoRoblox● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged task is backed by nine earlier author-written Roblox interview reports and a Sep 2, 2026 source slide. The slide directly supports simultaneous per-user and per-experience limits, one shared cap, accepted-only accounting, and exclusion of denied requests. It omits the exact window-endpoint convention, so the practice uses (t - windowLength, t]; its boolean result is represented as 1/0 integers by the runner. The judged task matches the available source at about 95%.

You are given a stream of requests in chronological order. Each request has a timestamp, a user id, and an experience id.

A request is accepted only when both of these limits still have capacity:

  • the number of accepted requests for the same user inside the active sliding window
  • the number of accepted requests for the same experience inside the active sliding window

Only accepted requests count toward future capacity. Denied requests are not stored. For a request at timestamp t, the active window is (t - windowLength, t], so accepted requests at timestamps less than or equal to t - windowLength are expired before checking the new request.

Return an integer array where 1 means the corresponding request is accepted and 0 means it is denied.

Function

rateLimiter(requestTimestamps: int[], userIds: int[], experienceIds: String[], windowLength: int, maxRequests: int) → int[]

Examples

Example 1

requestTimestamps = [1, 2, 3, 4, 5]userIds = [1, 1, 2, 1, 2]experienceIds = ["A", "A", "A", "A", "B"]windowLength = 3maxRequests = 1return = [1, 0, 0, 1, 1]

The second request is denied because user 1 already has an accepted request in the window. The third request is denied because experience A already has an accepted request in the window. At timestamp 4, the timestamp 1 request has expired, so user 1 and experience A both have capacity.

Example 2

requestTimestamps = [10, 11]userIds = [1, 2]experienceIds = ["game-1", "game-1"]windowLength = 10maxRequests = 1return = [1, 0]

The second user has no accepted request yet, but the shared experience has already reached its limit.

Example 3

requestTimestamps = [1, 2, 3, 4]userIds = [7, 7, 7, 7]experienceIds = ["A", "A", "A", "A"]windowLength = 3maxRequests = 2return = [1, 1, 0, 1]

The denied request at timestamp 3 is not stored. Before timestamp 4 is checked, the accepted timestamp 1 request expires.

Constraints

  • requestTimestamps.length == userIds.length == experienceIds.length
  • requestTimestamps is sorted in nondecreasing order.
  • windowLength > 0
  • maxRequests > 0

More Roblox problems

  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public int[] rateLimiter(int[] requestTimestamps, int[] userIds, String[] experienceIds, int windowLength, int maxRequests) {
      // write your code here
    }
}
Checking account…