Hi, here’s your problem today. This problem was recently asked by Google:
You are given a stream of numbers. Compute the median for each new element .
Eg. Given [2, 1, 4, 7, 2, 0, 5], the algorithm should output [2, 1.5, 2, 3.0, 2, 2, 2]
Here’s a starting point:
def running_median(stream):
# Fill this in.
running_median([2, 1, 4, 7, 2, 0, 5])
# 2 1.5 2 3.0 2 2.0 2