DIFFICULTY
  • School
  • Basic
  • Easy
  • Medium
  • Hard
STATUS
  • Solved
  • Unsolved



Loading...

Leaderboard
Showing:
Median of 2 Sorted Arrays of Different Sizes
Hard Accuracy: 43.85% Submissions: 3331 Points: 8

Given two sorted arrays array1 and array2 of size m and n respectively. Find the median of the two sorted arrays.

Example 1:

Input:
m = 3, n = 4
array1[] = {1,5,9}
array2[] = {2,3,6,7}
Output: 5
Explanation: The middle element for
{1,2,3,5,6,7,9} is 5

Example 2:

Input:
m = 2, n = 4
array1[] = {4,6}
array2[] = {1,2,3,5}
Output: 3.5

Your Task:
The task is to complete the function MedianOfArrays() that takes array1 and array2 as input and returns their median. 

Expected Time Complexity: O(min(log n, log m)).
Expected Auxiliary Space: O(1).

Constraints: 
0 <= m,n <= 10000
1 <= array1[i], array2[i] <= 10^5

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Median of 2 Sorted Arrays of Different Sizes

Output Window