Problem · Sliding Window

Rate Limiter Sliding Window With Per-Entity Limits

Learn this problem
MediumRobloxPHONE SCREEN
See Roblox hiring insights

Problem statement

Source note, June 26, 2026: Please ignore this question for now, as it may have source issues. If you still want to practice it, treat it as a rough draft rather than a reliable source-backed problem. I will investigate and clean it up later, but this may take a while. Sorry for the inconvenience, and thank you so much for your understanding. You are the best! 🐠

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

drafts saved locally
public int[] rateLimiter(int[] requestTimestamps, int[] userIds, String[] experienceIds, int windowLength, int maxRequests) {
  // write your code here
}
requestTimestamps[1, 2, 3, 4, 5]
userIds[1, 1, 2, 1, 2]
experienceIds["A", "A", "A", "A", "B"]
windowLength3
maxRequests1
expected[1, 0, 0, 1, 1]
checking account