Amazon Interview Question
Software Engineer / DevelopersIn my opinion: when it is asked about "data structures", they mean to store stuff in main memory. So a Trie would certainly be the best in this case, where the tree height will be no more than the length of the data (zipcode or SSN). The height will be even shorter if we take multi-stride tries.
http://en.wikipedia.org/wiki/Trie
Arrays will take O(n) comparisons to retrieve data, and hashtables waste storage space.
you have to ask yourself what the data will be used for. SSN and area code are will probably be assigned to a person with a potential personID. Given a personID you should be able to quickly retrieve his/her data. Hash table would be ideal. arrays would work if the index of the element is also the ID passed in.
Before going into technical details I would ask if we have clearance from the Legal Department to store SSNs ;)
For fast retrieval and search of zip codes, I will go wid Trie Tree
- Aryan October 30, 2008