Gamified challenge · Two heaps
prices are trade prices arriving one at a time. After each trade, report the median of all prices so far: the middle one when the count is odd, the average of the two middle ones when it is even.
A median can end in .5, so to keep answers exact report twice the median as an integer. Write medians(prices) returning one number per trade.
Example: [5, 15, 1, 3] → medians 5, 10, 5, 4 → return `[10, 20, 10, 8]`.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google