Find the median value of two sorted arrays without fully merging them.
You are given two sorted integer arrays. Your task is to compute the median of the combined multiset formed by all elements from both arrays.
The solution should be more efficient than merging the arrays into one full sorted array when possible. The median is the middle value in the sorted order, or the average of the two middle values when the total number of elements is even.
nums1 and nums2.Example 1
Input
nums1 = [1, 3] nums2 = [2]
Output
2.0
Explanation
The merged order is [1, 2, 3]. The middle value is 2.
Example 2
Input
nums1 = [1, 2] nums2 = [3, 4]
Output
2.5
Explanation
The merged order is [1, 2, 3, 4]. The median is the average of 2 and 3, which is 2.5.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.