Running Median
You are given a stream of 'N' integers. For every 'i-th' integer added to the running list of integers, print the resulting median.
Print only the integer part of the median.
Input Format :
The first line of input contains an integer 'N', denoting the number of integers in the stream.
The second line of input contains 'N' integers separated by a single space.
Output Format :
Print the running median for every integer added to the running list in one line (space-separated).
Input Constraints
0 <= N <= 10 ^ 5
1 <= ARR[i] <= 10 ^ 5
Time Limit: 1 sec
CodingNinjas
author
2y
Sorting Approach
The median of n numbers is the middle-most element among the numbers when sorted in ascending order, when n is odd, and is the average of the two middle-most elements, when n is even. ...read more
CodingNinjas
author
2y
Inserting At Correct Position
According to the previously discussed approach, every time there is a new addition, we have a sorted array right before the addition. Instead of sorting it again, we can s...read more
CodingNinjas
author
2y
Min And Max Heap Approach
The idea is to maintain two equal halves of the current stream: the higher half containing greater valued elements, and the lower half containing lower valued element. For eac...read more
Add answer anonymously...
Top Google Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Google Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app