Loading...
Loading...
Loading...
Numbers arrive one at a time. After each one, print the median of all numbers so far with one digit after the decimal point. For an even count, the median is the average of the two middle numbers.
Example 1
Input
5 5 2 8 1 9
Output
5.0 3.5 5.0 3.5 5.0
The medians are 5.0, 3.5, 5.0, 3.5, 5.0.
Example 2
Input
1 4
Output
4.0
Try the problem first. Open one hint at a time.
Keep the smaller half in a max-heap (negated values) and the larger half in a min-heap.
After each insert, make the sizes equal or let the smaller half have one extra.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor