Dsa
Heap
Easy
Median of Streaming Numbers
You are tasked with analyzing a stream of integers. Implement a program that maintains the current median of a stream of numbers after each new number is added. The program should read a sequence of integers until EOF, one integer per line, and print the median after each number. If the total count of numbers is odd, the median should be the middle number. If it’s even, the median should be the average of the two middle numbers, rounded to two decimal places.
Example:
Input:
1
5
2
4
3
Output:
1.00
3.00
2.00
3.00
3.00
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