Java: Median of Two Sorted Arrays of Different Sizes

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:30:00

Lab Details

Difficulty Level: HARD

Problem Statement:

Given two sorted arrays, a[] and b[], the task is to find the median of these sorted arrays, where N is the number of elements in the first array, and M is the number of elements in the second array.

Input:

a[] = {2, 3, 5, 8}, b[] = {10, 12, 14, 16, 18, 20}

Output:

The median is 11.

The merged array is: ar3[] = {2, 3, 5, 8, 10, 12, 14, 16, 18, 20}

If the number of the elements are even. So there are two middle elements.

Take the average between the two: (10 + 12) / 2 = 11.


Self-paced Membership
  • 22+ Courses
  • 750+ Hands-On Labs
  • 200+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A
  • 10+ Real-world Projects
  • Career Coaching
  • Email Support
Upto 66% OFF
KNOW MORE..

To get full access to all courses

Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this