Median of Two Sorted Arrays

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity must be O(\log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. 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
C++Binary Search
00
Read

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the combined sorted arrays. The solution must provide an overall run-time complexity of O(log(m+n)). Example: Input: nums1 = [1, 3], nums2 = [2] Output: 2.00000 Explanation: Combined array = [1, 2, 3] and median is 2. Input: nums1 = [1, 2], nums2 = [3, 4] Output: 2.50000 Explanation: Combined array = [1, 2, 3, 4] and median is (2 + 3) / 2 = 2.5. Constraints: 0 <= m, n <= 1000 1 <= m + n <= 2000 -10^6 <= nums1[i], nums2[i] <= 10^6
JavaBinary Search
00
Read

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(\log(m+n)). 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
JavaBinary Search
00
Read

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the combined sorted array. The solution must achieve an overall runtime complexity of O(\log(m+n)) or better. You may assume both arrays are sorted in non-decreasing order and are not both empty.
JavaBinary Search
00
Read

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The solution must achieve an overall run time complexity of O(log(min(m, n))). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Constraints: nums1.length == m nums2.length == n 0 <= m, n <= 1000 1 <= m + n <= 2000 -10^6 <= nums1[i], nums2[i] <= 10^6
PythonBinary Search
00
Read
1
InterviewGPT

AI-powered tools to help you succeed in tech interviews — from resume to offer.

Interview Solver

  • Coding Puzzles
  • System Design
  • Behavioral Challenges
  • ML System Design
  • SQL Puzzles
  • FE System Design
Explore Solver

Question Bank

  • Coding Interview Questions
  • System Design Interview Questions
  • Behavioral Interview Questions
  • ML System Design Questions
  • SQL & Database Questions
  • FE System Design Questions
Explore Questions

Golden Blogs

  • Coding Solutions
  • System Design Guides
  • Behavioral Guides
  • ML System Design Guides
  • SQL Solutions
  • FE System Design Guides
Explore Blogs

Intervipedia

  • Coding Concepts
  • System Design Concepts
  • Behavioral Concepts
  • ML System Concepts
  • SQL Concepts
  • FE System Concepts
Explore Concepts

Application Tools

  • Self-Intro Generator

Company

  • Pricing
  • FAQ
  • About
  • Privacy Policy
  • Terms of Service

© 2026 InterviewGPT Inc. All rights reserved.

All systems operationalUS-East

Made with ♥ for developers