Amazon Interview Question: 2SUM with Hashtable... | Glassdoor

Interview Question

Software Engineer Interview Seattle, WA

2SUM with Hashtable


Interview Answer

2 Answers


Loop through array, dump each element in a HashSet.
Second iteration, check if set.Contains(sum - element[i])

Interview Candidate on May 14, 2014

while this is the idea, I believe you need a hasmap with occurrences as values. Imagine you have 12 3 4 5 and sum is 10. With a hashmap you will get pair (5,5) which is not correct since there is only one 5 in the array.

By the way, the exact sum and binary tree lcs questions were asked at IBM interview as well. Funny!

mee on Jul 8, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.