# There are 2 sorted arrays A and B of size n each. # find the median of the array obtained after merging the above 2 arrays(i.e. array of length 2n). #Algorithm :Binary-search #Time-complexity:O(logn),Auxiliary-space: O(1) def get_median(a,a1,lo1,hi1,lo2,hi2) #Length of the arrays len=hi1-lo1+1 return -1 if len<=0 # return -1 if array is empty or invalid return (a[lo1]+a1[lo2])/2 if len==1 # return median if each array is of size 1 return ([a[lo1], a1[lo2]].max + [a[hi1], a1[hi2]].min)/2 if len==2 # return median if each array is of size 2 #Median and index of median of array 1 m1,m1_i=median(a,len,lo1) #Median and index of median of array 2 m2,m2_i=median(a1,len,lo2) #Compare medians if equal return either m1 or m2, #else if m1m2 median lies in m1,hi1 and lo1,m2 if m1==m2 return m1 elsif m1 4