Question bank › Heap
Dsa Heap Hard

Median of Running Numbers

You’re asked to maintain a dynamic list of integers. Implement a function to process a stream of integers and output the median after each insertion. Use a heap-based approach: maintain a max-heap for the lower half of numbers and a min-heap for the upper half. Input Format: The first line contains an integer n (1 <= n <= 1000), the number of integers that will be streamed. The next n lines each contain a single integer x (0 <= x <= 10^6). Output Format: After each integer is processed, output the current median, formatted to 1 decimal place. Example: Input: 3 1 2 3 Output: 1.0 1.5 2.0

Key concepts

heapmediandata_stream

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.