Middle of Two Sorted Lists

HardBinary Search≈ 60 min

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

text
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]       →  10

In 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).
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
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.