Google Interview Question

Find the common numbers in two text files.

Interview Answers

Anonymous

Aug 1, 2013

Liron, HashMap is a bad choice for strings especially when you have large files since you'll have to many collisions. (There's way to many possible strings than the possible int values). I would choose at least a trie for your solution. You can still get along with hashmap in the case of numbers if the numbers don't exceed an int.

Anonymous

Feb 4, 2012

Considering you ment the common strings. hash every string from the first file O(n), search every string from the second file int the hash O(n).