You are given two sorted arrays nums1[] and nums2[] of sizes m and n. Your task is to find the median of the two sorted arrays. The median is the middle element when all elements from both arrays are combined and arranged in sorted order. If the total number of elements is even, the median is the average of the two middle elements.
Example 1
Input: nums1 = [1,3], nums2 = [2]
Output: 2.0
Explanation: Combined sorted array is [1,2,3]. The middle element is 2, so the median is 2.0.
Example 2
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.5
Explanation: Combined sorted array is [1,2,3,4]. The two middle elements are 2 and 3. The median is (2 + 3) / 2 = 2.5.
Example 3
Input: nums1 = [0,0], nums2 = [0,0]
Output: 0.0
Explanation: Combined sorted array is [0,0,0,0]. The two middle elements are 0 and 0. The median is (0 + 0) / 2 = 0.0.
Sign in to write, run, and submit your solution against the full test suite.