Block interview question
Rate limit requests with separate sliding windows per user and per experience
- Company:
- Block
- Round:
- Phone screen
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- Q3 2025
Problem
This is the follow-up to a global rate limiter. Requests arrive in order: request i has a timestamp timestamps[i], a user id user_ids[i] and an experience id experience_ids[i]. You are also given window_length and max_requests.
Keep an independent sliding window for every user and another for every experience, all with the same window_length and max_requests. Process the requests in order and return a list of booleans, one per request:
- A request at time
tis allowed only if its user has fewer thanmax_requestsallowed requests with timestamps in(t - window_length, t]and its experience also has fewer thanmax_requestsallowed requests in that interval. - An allowed request counts toward both its user's window and its experience's window. A denied request counts toward neither.
Example 1
Input: timestamps = [1, 2, 3, 4, 5], user_ids = [1, 1, 2, 1, 2],
experience_ids = ["A", "A", "A", "A", "B"], window_length = 3, max_requests = 1
Output: [True, False, False, True, True]
Request 2 is denied because user 1 already used its single slot at time 1; request 3 has a fresh user but experience A is still full; at time 4 the request from time 1 has left both windows.
Example 2
Input: timestamps = [1, 2, 2, 3, 5, 6], user_ids = [1, 2, 1, 1, 2, 1],
experience_ids = ["A", "B", "A", "B", "A", "A"], window_length = 4, max_requests = 2
Output: [True, True, True, False, True, True]
The fourth request is denied because user 1 already has two allowed requests (at times 1 and 2) in its window, even though experience B has room.
Constraints
- The three lists have the same length, which may be 0.
timestampsis sorted in non-decreasing order.- User ids and experience ids are tracked separately, even if some values look alike.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern