Question bank › Heap
Dsa Heap Hard

Median Stream

Write a program that maintains the median of a stream of integers, each added one at a time. The program should output the median after each addition. You should implement a class `MedianFinder` that provides an `addNum(num: int) -> None` method to add a number and a `findMedian() -> float` method to return the current median. ### Input The first line contains an integer `n` (0 ≤ n ≤ 10^5), which is the number of integers to process. The next `n` lines each contain one integer `num` (-10^9 ≤ num ≤ 10^9). ### Output For each addition to the stream, print the current median value. ### Example Input: 3 1 2 3 Output: 1.0 1.5 2.0

Key concepts

heapmedianstreaming

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.