Running Median Problem
Given a stream of integers, calculate and print the median after each new integer is added to the stream.
Output only the integer part of the median.
Example:
Input:
N = 5
Stream = [2, 3, 4, 1, 6]
Output:
2 2 3 2 3
Constraints:
0 ≤ N ≤ 10^5
1 ≤ ARR[i] ≤ 10^5
- Time Limit: 1 sec

AnswerBot
4mo
Calculate and print the median after each new integer is added to the stream.
Use two heaps - a max heap to store the smaller half of the numbers and a min heap to store the larger half.
Keep the sizes ...read more
Help your peers!
Add answer anonymously...
Google Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. What are your goals?
A Software Developer was asked 2mo agoQ. What is Dijkstra's algorithm and how does it work?
A Software Developer was asked 2mo agoQ. What is the explanation of the Least Recently Used (LRU) cache algorithm?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. What are your goals?
A Software Developer was asked 2mo agoQ2. What is Dijkstra's algorithm and how does it work?
A Software Developer was asked 2mo agoQ3. What is the explanation of the Least Recently Used (LRU) cache algorithm?
Top HR questions asked in Google Software Developer
A Software Developer was asked 2mo agoQ1. Why should we choose you?
A Software Developer was asked 3mo agoQ2. How does the role fit your career plans?
A Software Developer was asked 8mo agoQ3. Explain your project in detail.
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

