Implement a thread-safe rate limiter
Company: Snapchat
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability to design and implement a thread-safe per-user API rate limiter, focusing on concurrency control, synchronization techniques, and time-based request accounting in the Coding & Algorithms domain.
Constraints
- requests are processed in arrival order
Examples
Input: ([('u', 0), ('u', 10), ('u', 20)], 2, 100)
Expected Output: [True, True, False]
Explanation: Third rejected.
Input: ([('u', 0), ('v', 1), ('u', 100)], 2, 100)
Expected Output: [True, True, True]
Explanation: Boundary evicts old request.
Input: ([], 2, 100)
Expected Output: []
Explanation: No requests.
Hints
- Use one deque of accepted timestamps per user.