← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE interview with a system design/coding question around building a hit counter. Pretty focused session, just the one problem but it had enough edge cases to keep you busy for the whole time.

Questions Asked (1)

Q1

Design a hit counter that tracks the number of hits received in the past 5 minutes (300 seconds), assuming hits arrive in chronological order. Implement initialization, a hit recording method, and a method to query the hit count at a given timestamp.

Algorithms & Data StructuresSystem Design
Author's notes

The 300-second sliding window is the crux of it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that hits arrive in chronological order, then propose a queue-based solution where each hit is stored with its timestamp. For getHits, remove hits older than timestamp - 300 and return the queue size, achieving O(1) amortized time per operation.

Pro tip: Mention that since timestamps are monotonically increasing, you can use a queue (or circular buffer) to avoid scanning all hits; this shows you understand the problem's constraints and can optimize for real-world scenarios.

1. Clarify requirements and constraints

Confirm that hits arrive in chronological order, that the window is exactly 300 seconds (inclusive), and that multiple hits can have the same timestamp. Ask about expected hit rate and memory constraints.

2. Choose data structure

Select a queue (e.g., deque) to store timestamps of hits, because it supports O(1) append and popleft operations. Alternatively, consider a circular buffer if the maximum number of hits per window is known.

3. Implement hit(timestamp)

Append the timestamp to the queue. Optionally, if using a fixed-size array, maintain a head index and overwrite old entries.

4. Implement getHits(timestamp)

While the queue is not empty and the front timestamp is <= timestamp - 300, remove it. Then return the queue size. This ensures only hits within the last 300 seconds are counted.

5. Analyze complexity and edge cases

State that each hit is added once and removed at most once, giving O(1) amortized time per operation and O(n) space where n is the number of hits in the window. Discuss edge cases like no hits, all hits expired, and boundary timestamps.

Key Points to Mention

  • Use a queue to store timestamps of hits, leveraging chronological order.
  • For getHits, remove expired hits (timestamp <= current - 300) from the front.
  • Time complexity: O(1) amortized per operation; space complexity: O(n) where n is hits in window.
  • Consider using a circular buffer if the maximum number of hits per window is known to bound memory.
  • Handle edge cases: empty queue, all hits expired, and hits exactly at the boundary (timestamp - 300).
  • Mention that this approach works for single-threaded scenarios; for concurrency, discuss locking or thread-safe data structures.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.