526. Median of Two Sorted Arrays

HardBinary SearchBinary SearchArray

Given two sorted arrays, find the median of the combined sorted order in O(log(min(m,n))) time. Because the median of integers may be a half-integer, return the median multiplied by 2 (which is always an integer): for an odd total this is 2 times the middle element, and for an even total it is the sum of the two middle elements. Input: '[a], [b]'.

Input: '[a], [b]'.

Output: Integer — the median multiplied by 2.

Examples

Example 1
Input: [1,3], [2]
Output: 4
Explanation: Median 2, doubled is 4.
Example 2
Input: [1,2], [3,4]
Output: 5
Explanation: Median 2.5, doubled is 5.
Example 3
Input: [], [1]
Output: 2
Explanation: Median 1, doubled is 2.

Constraints

Asked by

AdobeBloombergAmazonMicrosoftGoogleMeta
Solve this problem in the editor →