FastPrepFind Median from Data Stream
Problems/Find Median from Data Stream

Find Median from Data Stream

Zillow logoZillow● HardFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow in 2013 and 2018. A Senior Software Engineer candidate in Seattle in 2018, who says the real goal was a manager role, got this task from the first onsite interviewer, next to a task on merging sorted lists. A Software Development Engineer Intern candidate in Seattle in 2013 lists it among the questions: pick a data structure so that the median is always ready while new numbers keep coming in. That report does not tie it to a round. It had a phone interview that covered how fast heap and binary tree operations are, and an onsite where three interviewers each asked for code. We place it in the phone interview because that is where the report puts questions about heap costs, and a structure built on heaps is the usual answer; this is our inference.

Neither report gives the operation names, the value type, limits, what happens before any number is added, a speed target, or how input reaches the code; the 2013 report does not say whether code was written. These choices are ours: the two operations are named addNum and findMedian, as in the well-known version of this task; values are integers from -100,000 to 100,000; for an even count the median is the average of the two middle numbers; findMedian only runs after at least one number was added. addNum should take O(log n) time and findMedian O(1) time; tests check only the results, so they cannot check this. A function gets the operations as two arrays of the same length (operation names, and values with 0 for each findMedian), with at most 10,000 operations, and returns the medians in order as decimal numbers.

Our version is about 85% the same as the reported question.

Numbers arrive one at a time. Build a structure that stores them and can report their median at any moment. The structure starts empty.

The median of a group of numbers is found after sorting them: it is the middle number when the count is odd, and the average of the two middle numbers when the count is even, so it can end in .5.

You get two arrays of the same length: operations and values. Run the operations from left to right. At index i, operations[i] is one of these:

  • "addNum": add values[i] to the structure.
  • "findMedian": add the median of all numbers added so far to the result. The stored numbers do not change.

Return the results of all "findMedian" operations, in the order they ran.

Each "addNum" should take O(log n) time and each "findMedian" should take O(1) time, where n is the number of values added so far.

Function

runMedianFinder(operations: String[], values: int[]) → double[]

Examples

Example 1

operations = ["addNum","findMedian","addNum","findMedian","addNum","addNum","findMedian","addNum","findMedian"]values = [6,0,10,0,2,7,0,3,0]return = [6.0,8.0,6.5,6.0]

After 6 the only number is 6. After 10 the two middle numbers are 6 and 10, so the median is 8.0. After 2 and 7 the sorted numbers are [2,6,7,10] and the median is (6 + 7) / 2 = 6.5. After 3 the sorted numbers are [2,3,6,7,10] and the middle one is 6.

Example 2

operations = ["addNum","addNum","findMedian","addNum","findMedian","addNum","findMedian"]values = [-4,-4,0,5,0,-1,0]return = [-4.0,-4.0,-2.5]

The first two numbers are both -4, so the median is -4.0. After 5 the sorted numbers are [-4,-4,5] and the middle one is still -4. After -1 they are [-4,-4,-1,5] and the median is (-4 + -1) / 2 = -2.5.

Example 3

operations = ["addNum","addNum","findMedian","findMedian"]values = [3,4,0,0]return = [3.5,3.5]

The median of 3 and 4 is 3.5. Asking for the median again without adding a number gives the same answer.

Constraints

  • 1 <= operations.length <= 10000
  • values.length == operations.length
  • Each operations[i] is "addNum" or "findMedian".
  • -105 <= values[i] <= 105
  • When operations[i] is "findMedian", values[i] is 0 and is not used.
  • Every "findMedian" runs after at least one "addNum".

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Tic-Tac-Toe Winner on a Huge BoardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2016
  • Most Frequent Three-Page SequencesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2016
  • Maximum Path Sum in a GridONSITE INTERVIEW · Seen Apr 2016

Similar questions at other companies

  • Find Median from Data StreamSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Top K With a Deterministically Noisy Comparator (MLE)Mercor · ONSITE INTERVIEWMercor interview questions
  • Find Median from Data StreamAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Find Median from Data StreamXPeng Motors · PHONE SCREEN
  • Find Median from Data StreamBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Median of a Number StreamAdobe · PHONE SCREENAdobe interview questions
  • Running Stream MediansCitadel · ONSITE INTERVIEWCitadel interview questions
  • Streaming Median of Trade PricesXantium · PHONE SCREEN
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public double[] runMedianFinder(String[] operations, int[] values) {
        // Write your code here.
    }
}
Checking account…