Update appNew update is available. Click here to update.

Running Median

Contributed by
Prateek_18cb
Last Updated: 23 Feb, 2023
Hard
yellow-spark
0/120
Avg time to solve 46 mins
Success Rate 50 %
Share
35 upvotes

Problem Statement

You are given a stream of 'N' integers. For every 'i-th' integer added to the running list of integers, print the resulting median.

Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1 :
6
6 2 1 3 7 5
Sample Output 1 :
6 4 2 2 3 4
Explanation of Sample Output 1 :
S = {6}, median = 6
S = {6, 2} -> {2, 6}, median = 4
S = {6, 2, 1} -> {1, 2, 6}, median = 2
S = {6, 2, 1, 3} -> {1, 2, 3, 6}, median = 2
S = {6, 2, 1, 3, 7} -> {1, 2, 3, 6, 7}, median = 3
S = {6, 2, 1, 3, 7, 5} -> {1, 2, 3, 5, 6, 7}, median = 4
Sample Input 2 :
5
5 4 3 2 1
Sample Output 2 :
5 4 4 3 3
Reset Code
Full screen
Auto
copy-code
Console