Implement sliding-window rate limiter with dual thresholds
Company: Atlassian
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Take-home Project
Quick Answer: This question evaluates a candidate's skill in implementing efficient online sliding-window rate limiting, covering stream processing, time-based window management, per-key state maintenance, algorithmic complexity analysis, and formal correctness reasoning.
Constraints
- Timestamp equals request index in seconds
Examples
Input: ([],)
Expected Output: []
Explanation: No requests.
Input: (['a', 'a', 'a'],)
Expected Output: ['200', '200', '429']
Explanation: Third request in five seconds rejected.
Input: (['a', 'b', 'a', 'b', 'a'],)
Expected Output: ['200', '200', '200', '200', '429']
Explanation: Limits are per URL.
Input: (['a', 'a', 'x', 'x', 'x', 'a', 'a'],)
Expected Output: ['200', '200', '200', '200', '429', '200', '200']
Explanation: Boundary at t=5 evicts t=0 from the five-second window.
Input: (['u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u'],)
Expected Output: ['200', '200', '429', '429', '429', '200', '200', '429', '429', '429', '200', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '429', '200', '200', '429', '429', '429']
Explanation: Long run only records successful requests.
Hints
- Keep successful timestamps only; evict entries older than 29 seconds.