Median of Two Sorted Arrays
Problem statement
Given two integer arrays first and second, each sorted in nondecreasing order, return the median of all their values.
At least one array is nonempty. Solve the problem in O(log(min(first.length, second.length))) time.
Function
medianTwoSortedArrays(first: int[], second: int[]) → doubleExamples
Example 1
first = [1,3]second = [2]return = 2.0The combined sorted order is [1,2,3], whose middle value is 2.
Example 2
first = [1,2]second = [3,4]return = 2.5The two middle values are 2 and 3, so their average is 2.5.
Constraints
0 <= first.length, second.length <= 1000001 <= first.length + second.length-10^9 <= first[i], second[i] <= 10^9- Both arrays are sorted in nondecreasing order