Running Median of Pickup ETAs as Requests Arrive

Last updated: November 29, 2026

Quick Overview

Pickup ETA estimates arrive one at a time. Implement add(eta) and median() so that median() returns the median of all ETAs seen so far, using the average of the two middle values for an even count.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Pickup ETA estimates arrive one at a time. Implement add(eta) and median() so that median() returns the median of all ETAs seen so far, using the average of the two middle values for an even count.

Uber technical screens use this to test the two-heap pattern in a setting close to real-time ETA monitoring dashboards. Interviewers want balanced heaps and a clear invariant.

What the Interviewer Expects
  • Uses a max-heap for the lower half and a min-heap for the upper half
  • Keeps sizes balanced so the lower half has equal or one more element
  • Moves the boundary element on every insert to preserve ordering
  • Returns the correct average for even counts
  • States O(log n) add and O(1) median
Key Topics to Cover
heaps
two heaps
streaming median
order statistics
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 support a sliding window of the last 1,000 ETAs?
  • What if you only need an approximate p50 over billions of values?
  • How would you extend this to the 90th percentile?
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
  • add(x) with numeric ETA in seconds, many calls.
  • median() after at least one add.
  • Even count returns the mean of the two middle values....
High-Level Design

Split the values into a lower half low (max-heap, stored as negatives) and an upper half high (min-heap). Invariant: every value in low is at most every value in high, and len(low) equals `l...


Submit Your Answer
Markdown supported