Middle of Two Sorted Lists
You are given two lists of integers, first and second, each sorted from smallest to largest. Together they hold an odd number of numbers. Put them together into one sorted list in your head, and return the number in its middle: the one with as many numbers before it as after it.
Examples
first = [1, 3], second = [2] → 2
first = [1, 2, 7], second = [3, 4, 5, 8] → 4
first = [], second = [5] → 5
first = [10, 20, 30], second = [1, 2] → 10In the second example the lists together are 1, 2, 3, 4, 5, 7, 8, and 4 has three numbers on each side.
Constraints
- Each list holds up to 100,000 numbers, sorted, each between -1,000,000,000 and 1,000,000,000; together they hold an odd number, so at least one.
- Aim for O(log(n + m)): merging the lists, even only up to the middle, is O(n + m).
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.