Median after each new number
Numbers arrive one at a time in the list nums. Return a list of the same length where item i is the median of the first i + 1 numbers. The median is the middle value once they are sorted; with an even count it is the mean of the two middle values, so it can end in .5 (whole medians pass as 4 or 4.0).
Values may repeat and may be negative. Aim for O(log n) per number instead of re-sorting each prefix.
Besides the tests, one large input (4,000 numbers) with a ~300 ms limit (scaled to your device's speed): brute force won't pass.
Examples
running_medians([5,3,8,1])→[5,4,5,4]running_medians([2,7])→[2,4.5]running_medians([1,2,3,4,5])→[1,1.5,2,2.5,3]