Level: Senior-Level
Round: Phone Screen · Type: Coding · Difficulty: 5/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Sliding Window, Rate Limiter
Location: San Francisco Bay Area
Interview date: 2025-11-25
I was asked to implement a rate limiter using the sliding window technique. The problem involves determining whether incoming requests should be allowed or rejected based on the number of requests within a given time...
I asked with the following question:
You are building a rate limiter for a backend system. Incoming requests arrive at times specified by the array timestamps. Your task is to determine, for each request, whether it should be allowed or rejected based on the following rule:
Return an array result where result[i] is set to true if the i-th request is allowed, and false if it is rejected.
Constraints:
1 ≤ timestamps.length ≤ 10^5 1 ≤ timestamps[i] ≤ 10^9 1 ≤ maxRequests ≤ 10^5 1 ≤ windowSize ≤ 10^9 timestamps is strictly increasing.
Example 1:
Input: timestamps = [1, 100, 200, 250, 350], maxRequests = 2, windowSize = 200
Output: [true, true, false, true, true]
Explanation:
Example 2:
Input: timestamps = [10, 20, 30, 40], maxRequests = 3, windowSize = 50
Output: [true, true, true, false]
Example 3:
Input: timestamps = [1, 2, 3, 10, 11, 12, 20, 21, 22, 23], maxRequests = 2, windowSize = 5
Output: [true, true, false, true, true, false, true, true, false, false]