LiteCode

Median of Two Sorted Arrays

HardArrayBinary SearchDivide and Conquer
Given two sorted arrays nums1 and nums2 of sizes m and n, return the median of the two sorted arrays. The overall runtime complexity should be O(log(m + n)). Input format for LiteCode: Line 1: first array encoded as m followed by m sorted integers Line 2: second array encoded as n followed by n sorted integers Use 0 for an empty array Output format: Print the median with exactly 5 digits after the decimal point.

Examples

Input: 2 1 3 1 2
Output: 2.00000
Input: 2 1 2 2 3 4
Output: 2.50000

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