Navratri Sale: Get Upto 30% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now

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
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this