My question is with reference to Method 2 of this link. Here two equal length sorted arrays are given and we have to find the median of the two arrays merged.
Here is a very simple solution.
Actually it need to merger two sorted array and then find the middle.
import java.util.Arrays;
public class MedianofTwoArray {
/**
* @param args
*/
public static void main(String[] args) {
int []array1= {1,2,3,4,5};
int []array2= {6,7,8,9,10};
int median;
median=findMedian(array1,array2);
System.out.println(median);
}
public static int findMedian(int []arr1,int []arr2) {
int [] tempArr=new int[arr1.length+arr2.length]; //creating an array of the length ,equals to sum of arr1 and arr2
int i=0;
int j=0;
int k=0;
while(i