Originally posted by Bala Krishna:
I was asked this question recently in an interview. The interviewer wanted to know how to get the intersection of two unsorted arrays. My answer was to use the brute-force approach - for each element in one array, check if the element exists in the second array by looping thru it. He asked for a better approach, and my answer was to construct a binary search tree using the first array and do a look up with the elements in the second array. He didn't seem satisfied. Are there any better ways of doing this? TIA.
Originally posted by Jason Liao:
The complexity of sorting algorithm is O(mLOG(m)), not O(LOG(m)!!!
O(n) to check the contents of the second