Dsa
Heap
Easy
Median from Data Stream
You are given a stream of integers. Your task is to find the median of the numbers in the stream after each new number is added. Print the current median after processing each integer.
Input format:
The first line contains an integer N (1 <= N <= 10000), the number of integers in the stream.
The next N lines each contain one integer.
Output format:
Print a single line containing the median after each number is added, separated by spaces.
Example:
Input:
5
1
5
2
4
3
Output:
1
3.0
2
3.0
3
Key concepts
heapmedianstream
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