Amazon Interview Question


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
4
of 4 vote

I am assuming you type in your search the contact(in this case freeninza) and it returns a phone linked to this contact. Using a Trie can help you on that and the time will be O(L) where L is the string lenght, in this case freeninza.

- marcelovox2 October 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

1) input name and find phone number
-- Trie structure for name (string), phone number as assocaited value.
-- Or hashtable (name as hash key), and link list as chaining (for name duplicatiion)
2) input phone number and find name
-- hash table
(phone number is unique, so use is as hash key)

- peter tang October 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The great thing about a trie is that it would provide functionality to easily facilitate partial searches, you type in the start of the persons name or phone number and you could return all leaf nodes that match that that prefix. Not sure how you could do this with a hashmap

- Anonymous October 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How can you do partial search in a trie?

- samir14341 December 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use trie data structure to store all phone numbers. insertion and search will take O(length of phone number). To display the numbers starting with one or more digits, then the complexity will be the O(prefix length)+O(number of children for the immediate prefix node * length of the remaining number from child nodes).

- Manikanta October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the same way names can be stored in a trie data structure, so that search, insertion and returning the data will be of same complexity as above.

- Manikanta October 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hash map would be the best i think with key as the name and value as the number

- itbrother October 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if two persons have a same name. how will you avoid collisions??

- Ram Pavan Bheemanadham October 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

If two persons have the same name, do you store them by the same name in ur phone book Ram? How do u know which number to call then? Think practically

- Amit December 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we could solve this problem using trie, and leaf node of trie will contains list of actual phone numbers, by this same keys could have multiple values,

- ashish June 27, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More