An API dashboard updates its "median response time" label after every request. The median of a list is its middle value after sorting, or the average of the two middle values for an even count.
Write runningMedians(times) that returns an array where entry i is the median of times[0..i]. Answers within 1e-5 are accepted. Aim for O(log n) work per new time.
Input: times = [5,2,8,1,9] Output: [5,3.5,5,3.5,5]
[5] → 5, [2, 5] → 3.5, [2, 5, 8] → 5, [1, 2, 5, 8] → 3.5, [1, 2, 5, 8, 9] → 5.
Input: times = [100] Output: [100]
A single time is its own median.
1 <= times.length <= 3 * 10^50 <= times[i] <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #394 Running Median Response Time. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.