Microsoft Interview Question

how to make it O(n)

Interview Answers

Anonymous

Dec 7, 2013

I think to achieve O(n) we need to use a hashtable.

1

Anonymous

Nov 13, 2013

1. Load the items of the array A into a HashSet S. Each insert will take amortized O(1) time. 2. Iterate through the integers of array B and check if the HashSet contains the integer. Each lookup also takes O(1) time. So the overall algorithm is O(n) time.