Epic Interview Question

find an intersection between integer arrays

Interview Answers

Anonymous

Sep 29, 2011

A faster way is to determine which is the smaller array, sort it, then use binary search to determine which of the larger array is in the smaller array. Total time complexity is O((n+m)log m) where m is the size of the smaller list and n is the size of the larger array. this is better than the previous answer which is n*m.

2

Anonymous

May 5, 2010

given arrays a and b dim c() z=0 for x= 0 to ubound(a) -1 for y= 0 to ubound(b) -1 if b(y) = a(y) then z=z+1 redim.preserve c(z) c(z-1) = b(y) endif next y next x