← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Went through a coding round for an SDE 2 role at Uber. The question was around hit counter design, I got through the approach and tradeoffs fine but ran out of time before fixing a failing edge case, and I think I also misstated a complexity that probably dinged my evaluation.

Questions Asked (1)

Q1

Design and implement a hit counter that tracks the number of hits in the past 5 minutes. Discuss brute force and optimized approaches, including complexity tradeoffs.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

Got through brute force and the optimized version pretty cleanly, tradeoffs discussion felt okay too.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (e.g., single-threaded vs. distributed, exact vs. approximate counts) and then present a brute-force solution using a list of timestamps with O(n) space and O(n) time per query. Then propose an optimized approach using a circular buffer of 300 buckets (one per second) with O(1) time per hit and O(1) space, discussing trade-offs like precision and memory.

Pro tip: Mention that in a real system like Uber, you'd likely use a distributed counter with sliding windows (e.g., Redis sorted sets or a ring buffer per shard) and discuss how to handle clock skew and eventual consistency.

1. Clarify Requirements

Ask about scale (hits per second), precision (exact vs. approximate), and whether the system is single-node or distributed. This shows you think before coding.

2. Brute Force Approach

Store all hit timestamps in a list; on query, filter out timestamps older than 5 minutes and return the count. Discuss O(n) time and space, and why it's inefficient for high throughput.

3. Optimized Approach

Use a circular buffer of 300 buckets (one per second) to store counts. On each hit, increment the current second's bucket; on query, sum all buckets. This gives O(1) time per hit and O(1) space (300 integers).

4. Discuss Trade-offs

Compare precision (brute force exact, bucket approach approximate within 1 second), memory (O(n) vs. O(1)), and concurrency (need locks or atomic operations). Mention that bucket approach can be extended to sliding window with finer granularity.

5. Handle Edge Cases and Scale

Address thread safety, clock drift, and distributed scenarios (e.g., sharding by user ID, using Redis sorted sets). Suggest monitoring and potential optimizations like lazy deletion.

Key Points to Mention

  • Time and space complexity of each approach (brute force O(n) vs. optimized O(1)).
  • Precision trade-off: exact counts vs. approximate counts with bucket granularity.
  • Concurrency: need for locks or atomic operations in multi-threaded environments.
  • Distributed systems: sharding, eventual consistency, and using external stores like Redis.
  • Memory efficiency: circular buffer uses fixed memory (300 integers) regardless of hit volume.
  • Clock skew and time synchronization issues in distributed settings.

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