Microsoft Interview Question

Write a program to find out the median of two sorted array.

Interview Answers

Anonymous

Jul 14, 2011

No need to use the extra space. You simply need to iterate through the arrays, always choosing the smallest number, until you have gone through (n1.Length+n2.Length)/2 elements.

3

Anonymous

Jul 13, 2011

To find the median of two sorted arrays can be a tricky question. Remember not to confuse median with mean here. Median represents the middle value for any given range of values. So, given two sorted arrays, we would need to do a megre combine step for them, where we iterate over both arrays ( as in Merge sort combine step ) and store all the values in another array whose size is sum of sizes of two given arrays. Then we calculate the middle element of this new array and that would be the median. Time Complexity would be O(N) and space complexity would be O(n1+n2).