Posts

Showing posts with the label median of two sorted arrays

Median of Two Sorted Arrays Java Program - The Coding Shala

Image
Home >> Interview Questions >> Median of two sorted arrays Median of Two Sorted Arrays Java Program There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assume nums1 and nums2 cannot be both empty. Example 1: nums1 = [1,2] nums2 = [3,4] The median is 2.5. Example 2 nums1 = [3] nums2 = [-1, -2] The median is -2. Median of Two Sorted Arrays Java Program Before solving this we'll see what is median and how to find it. So basically a median is the value present at the center of a sorted array. Now the length of the array can be odd or even.  let's solve the median of two sorted arrays. Method 1: We have two sorted arrays, now if we merge both arrays into one(still sorted) then we can easily find the center of the merged array, But this method takes...