Rate Limiter Sliding Window With Per-Entity Limits
Learn this problemProblem 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]Example 2
requestTimestamps = [10, 11]userIds = [1, 2]experienceIds = ["game-1", "game-1"]windowLength = 10maxRequests = 1return = [1, 0]Example 3
requestTimestamps = [1, 2, 3, 4]userIds = [7, 7, 7, 7]experienceIds = ["A", "A", "A", "A"]windowLength = 3maxRequests = 2return = [1, 1, 0, 1]Constraints
requestTimestamps.length == userIds.length == experienceIds.lengthrequestTimestampsis sorted in nondecreasing order.windowLength > 0maxRequests > 0
More Roblox problems
- Most Frequent Call Stack Per ThreadPHONE SCREEN · Seen Jul 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026
- Meeting Rooms IIPHONE SCREEN · Seen Jun 2026
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Jun 2026
- Single-Threaded CPUPHONE SCREEN · Seen Jun 2026
- Sliding Window: Target Containment and Most-Repeated WindowPHONE SCREEN · Seen Jun 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · Seen Jun 2026
- Merge IntervalsPHONE SCREEN · Seen May 2026