4. Median of Two Sorted Arrays
HardBinary Search
Given two sorted arrays `nums1` and `nums2` of sizes m and n respectively, return the median of the two sorted arrays combined. The median is the middle value when all elements are arranged in order. If the total number of elements is even, the median is the average of the two middle values. For example, given nums1 = [1,3] and nums2 = [2], the merged array is [1,2,3] and the median is 2.0. Given nums1 = [1,2] and nums2 = [3,4], the merged array is [1,2,3,4] and the median is (2+3)/2 = 2.5.
Examples
Input: [1,3] [2]
Output: 2.0
Explanation: Merged array is [1,2,3]. The median of 3 elements is the middle one: 2.0.
Constraints
- nums1.length == m
- nums2.length == n
- 0 <= m <= 1000
- 0 <= n <= 1000
- 1 <= m + n <= 2000
- -10^6 <= nums1[i], nums2[i] <= 10^6
Loading...
Run checks all cases above. Submit evaluates all test cases.