10107

What is the Median?
Type: Sorting & Searching  
Diff: 5.0

Tricks

The confusing thing of this problem is to understand the input and output. In the given input, after 1 the list will be 1 and the median is 1. Again after 3 the list will be 1,3 and the median (3+1)/2 = 2; and after 4 the list will be 1,3,4 and the median will be 3, and after 60 the list will be 1,3,4,60 and the median will be (4+3)/2 = 3 (not 3.5). And so on�.

Another thing have to mentioned is that, the input limit is less than 2^31 , that is it can be hold by a 32 bit integer or long int. But calculating the median add two number will become larger than a 32 bit integer. So that you have to use double (not float - by Shahriar Manzoor). The output will be the integer part. But using %.0f  will not give the correct output. You need to use the floor() function.

And the last thing is that the input data will not be ordered. So you have to make them ordered. And insertion sort is better for this type of sorting (I think).

Related Problems & Topics

 

If you have any advice, complements 

or proposal, please  Send mail to Author

Submit

 

1