Bloomberg interview question

Design a sorting algorithm and/or data structure to find all the data members from one array that exist in another array. What would be the time complexity of a large data set or a small data set.

Interview Answer

Anonymous

30 Aug 2010

Do a sort on both arrays. For the ith item in array0 do a binary search for the same item in array 1. If the (i+1)th item in array0 = ith item in array0, skip the search and go to the (i+2)th item.