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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
design a data structure
sliding window
queue
rate counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • hit(t) and count(t) with non-decreasing t in 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...


Submit Your Answer
Markdown supported