Google interview question

Find the common numbers in two text files.

Interview Answers

Anonymous

1 Aug 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

4 Feb 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).