PIXELBANKv9.1.0
Menu

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays.

The overall run time complexity should be O(log(m+n)).

Output the median as a float with one decimal place.

Example:

Input:
1,3
2
Output:
2.0
Reasoning:
  • The input arrays are nums1 = [1, 3] and nums2 = [2].
  • We merge the two sorted arrays to get a single sorted array: [1, 2, 3].
  • The length of the merged array is 33, which is odd, so the median is the middle element: 22.
  • The final output is the median as a float with one decimal place: 2.02.0

Constraints:

  • 0 <= len(nums1), len(nums2) <= 1000
  • -10^6 <= nums1[i], nums2[i] <= 10^6
  • At least one array is non-empty
solution.py

Test Results

0/0
Run code to see test results.
Median of Two Sorted Arrays - Hard | PixelBank