Count Ride Requests Seen in the Trailing Five Minutes
Last updated: November 29, 2026
Quick Overview
Implement hit(timestamp) to record a ride request and count(timestamp) to return the number of requests in the past 300 seconds, including the current second. Timestamps are in seconds and never decrease.
Uber
November 29, 20260
0
0 solved
Implement hit(timestamp) to record a ride request and count(timestamp) to return the number of requests in the past 300 seconds, including the current second. Timestamps are in seconds and never decrease.
A common Uber phone screen warm-up related to request-rate monitoring for surge signals. The interviewer checks a sliding window with eviction and asks how memory behaves under heavy traffic.
What the Interviewer Expects
- Stores timestamps with counts so a burst in one second is one entry
- Evicts entries older than the window on every call
- Keeps a running total for O(1) count after eviction
- Explains the 300-bucket circular array alternative
- Discusses concurrency and multi-host aggregation
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you handle thousands of hits per second across many hosts?
- Use a fixed array of 300 buckets instead of a deque.
- What if timestamps can arrive slightly out of order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
hit(t)andcount(t)with non-decreasingtin seconds.- Window covers
(t - 300, t]. - Many hits can share one timestamp....
High-Level Design
Keep a deque of [timestamp, hits] pairs and a running total. On hit, if the last pair has the same timestamp, increment it, otherwise append a new pair, and add one to the total. Before any answer...