Median of Two Sorted Arrays

Hard

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

The overall run time complexity should be O(log (m+n)).

The tests accept a result within 1e-5 of the expected value.

Example 1

findMedianSortedArrays()
Input
nums1 = [1,3], nums2 = [2]
Output
2.00000

Why

Merged array = [1,2,3], median = 2.

Example 2

findMedianSortedArrays()
Input
nums1 = [1,2], nums2 = [3,4]
Output
2.50000

Why

Merged array = [1,2,3,4], median = (2 + 3) / 2.
Constraints
nums1.length == m, nums2.length == n
0 <= m, n <= 1000
1 <= m + n <= 2000

Topics

ArraysBinary SearchDivide and Conquer

Implement findMedianSortedArrays in the editor and return the answer — printing it is never graded.