CT030

Running Median Stream

HardAcceptance: 0.0%

The Codetikki astronomers record cosmic events as a stream of numbers. After each event, they must report the median of all events seen so far. Given a stream of numbers, print the median of the list so far after each new element. Recall that the median of an even-numbered list is the average of the two middle numbers.

Example 1:

Input: 7 2 1 5 7 2 0 5
Output: 2 1.5 2 3.5 2 2 2

Example 2:

Input: 3 1 2 3
Output: 1 1.5 2

Constraints:

1 <= n <= 10^5 -10^9 <= num <= 10^9

Tags:

heap design data-structures
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki