Sliding Window Rate Limiter
Implement a rate limiter using a sliding window algorithm that tracks and limits the number of requests allowed within a given time window. Extend the solution to support rate limiting at multiple granularities, including per IP address, per user, and per experience.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early August, 2026
Early August, 2026
Level 1 Implement a rate limiter that checks if requests exceed maximum allowed within a sliding window. Example: Input: requestTimestamps = [1, 2, 3, 4, 5, 6] windowLength = 3 maxRequests = 2 Output: [True, True, False, True, True, False] Explanation: Request at t=1: No previous requests → Allow (0 requests in window) Request at t=2: 1 request in window [max(0, 2-3), 2] → Allow (1 request) Request at t=3: 2 requests in [0, 3] (at t=1 and t=2) → Deny (would be 3rd) Request at t=4: Check window [1, 4]. Request at t=1 outside, t=2 inside → Allow Request at t=5: Check window [2, 5]. Only t=4 inside → Allow (1 request) Request at t=6: Check window [3, 6]. Requests at t=4, t=5 → Deny (would be 3rd) Level 2 (follow-up) Extend rate limiter to track limits PER USER and PER EXPERIENCE independently. Deny request if EITHER user limit OR experience limit is exceeded. Example: Input: requestTimestamps = [1, 2, 3, 4, 5] userIds = [1, 1, 2, 1, 2] experienceIds = ["A", "A", "A", "A", "B"] windowLength = 3 maxRequests = 1 Output: [True, False, False, True, True] Explanation: Request 0 (t=1, user=1, exp=A): First request → Allow Request 1 (t=2, user=1, exp=A): User 1 already has 1 request in [0,2] → Deny Request 2 (t=3, user=2, exp=A): Experience A has 1 request in [0,3] (at t=1) → Deny Request 3 (t=4, user=1, exp=A): User 1's previous at t=1 outside window [1,4]; Exp A's previous at t=1 also outside → Allow Request 4 (t=5, user=2, exp=B): User 2 OK (t=3 outside [2,5]), new exp B → Allow
Early July, 2026
Hello Interview Premium
Your account is free and you can post anonymously if you choose.