An API dashboard shows the median response time of the last batch of requests. times is unsorted. If the count is odd, the median is the middle value in sorted order; if it is even, it is the average of the two middle values.
Write medianTime(times) that returns the median. Answers within 1e-5 count as correct. Aim for average O(n) time.
Input: times = [120,80,200,95,110] Output: 110
Sorted: 80, 95, 110, 120, 200. The middle is 110.
Input: times = [40,10,30,20] Output: 25
Sorted: 10, 20, 30, 40. The middle two average to 25.
1 <= times.length <= 2 * 10^50 <= times[i] <= 10^6Run 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 #215 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.