Median of Two Sorted Arrays
Given two sorted arrays nums1 and nums2 of sizes m and n, return the median of the combined sorted array. The overall run time must be O(log(m + n)).
Open official problem prompt ↗Compute the median of two sorted arrays as if they were merged, but in logarithmic time by locating the correct split instead of building the merge.
Like two sorted stacks of numbered cards laid side by side: you slide a divider across both stacks at once until every card left of it is smaller than every card right of it. That divider marks the median.
- Input
- nums1 = [1, 3], nums2 = [2]
- Output
- 2.0
- Why
- Merged the arrays are [1, 2, 3]; the middle element of an odd-length total is 2.
nums1.length == mnums2.length == n0 <= m <= 10000 <= n <= 10001 <= m + n <= 2000-10^6 <= nums1[i], nums2[i] <= 10^6