← Atlassian Interview Insights
I knew sliding window conceptually but freezing up on the dual-window constraint cost me time.
Start by clarifying the problem: the function processes a stream of URLs, one per second, and must decide for each whether to allow (200) or reject (429) based on per-address rate limits. Then, design a solution using a sliding window or token bucket approach, maintaining per-address request timestamps, and check both limits before allowing a request. Finally, discuss trade-offs between memory usage and accuracy, and consider edge cases like bursts and concurrency.
Pro tip: Emphasize that the two limits must be enforced simultaneously, and that a request is allowed only if it satisfies both. Also, mention that using a deque per address to store timestamps is efficient for sliding window checks.
Confirm that the function receives URLs one per second, and must return '200' or '429' for each. Clarify that limits are per address (e.g., domain or IP) and that both limits apply concurrently.
Use a hash map to store per-address request timestamps. For each address, maintain a deque (or list) of timestamps of allowed requests within the last 30 seconds.
For each incoming request, remove timestamps older than 30 seconds. Then check if the number of requests in the last 30 seconds is < 5 and in the last 5 seconds is < 2. If both, allow and append current timestamp; else reject.
Consider what happens if multiple requests arrive simultaneously (though problem says one per second). Discuss memory growth and cleanup of old addresses. Optionally, mention token bucket as an alternative.
Time complexity per request is O(1) amortized (since we only remove old timestamps). Space is O(N) where N is number of active addresses. Discuss trade-offs between exact sliding window and approximate methods.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.