A web performance report lists the transfer size of every page on a site in kilobytes. The report shows the median size: the middle value after sorting, or the average of the two middle values when there is an even number of pages.
Write medianWeight(weights) that returns the median. weights is not sorted and has at least one value. Answers within 1e-5 are accepted.
Input: weights = [300,120,450] Output: 300
Sorted: 120, 300, 450. The middle is 300.
Input: weights = [80,20,60,40] Output: 50
Sorted: 20, 40, 60, 80. The middle two average to (40 + 60) / 2 = 50.
1 <= weights.length <= 10^50 <= weights[i] <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #393 Median Page Weight. 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.