Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Median of Two Sorted Arrays

Hard
binary-searcharraydivide-and-conquer

Given two sorted arrays nums1 and nums2, return the median of the combined sorted data. The intended solution runs in O(log(min(m, n))).

Input

  • Line 1: space-separated integers nums1 (may be empty)
  • Line 2: space-separated integers nums2 (may be empty)

Output: the median with two decimal places (the template formats it).

Example 1
Input:
1 3
2
Output:
2.00

Merged: [1,2,3], median 2.

Example 2
Input:
1 2
3 4
Output:
2.50

Merged: [1,2,3,4], median (2+3)/2.

Constraints

  • 0 ≤ m, n ≤ 1000, m + n ≥ 1
  • -10^6 ≤ values ≤ 10^6
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.