Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

66. Median of Two Sorted Arrays

HardDay 19 of 60Binary Search

You are given two sorted arrays nums1 and nums2 of sizes m and n. Return the median of all m + n numbers taken together. The overall run time should be O(log(m + n)).

Example 1
Input: nums1 = [1,3], nums2 = [2]
Output: 2.0
Merged: [1,2,3], the median is 2.
Example 2
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.5
Merged: [1,2,3,4], the median is (2 + 3) / 2.
Constraints
  • 0 <= m, n <= 1000
  • 1 <= m + n <= 2000
  • -10^6 <= nums1[i], nums2[i] <= 10^6
Hints
Frequently asked at: Google, Amazon, Microsoft, Apple, Goldman Sachs
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min