Amazon Interview Question for Software Engineer in Tests






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

Although hash map would give you the fastest lookup, I think the right data structure here is a trie. This is so because when you type Jo, we want to list
Joana
Joe
John
Joseph
.....

- Jasmeet April 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hash Map only works when complete key is given....trie works even in partial key or incomplete key...
like if you have following enteries
Joe
John

then searching for jo will return you nothing in hashmap but in trie you will get all possible combination

- Anonymous April 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Right, that was the idea behind the trie suggestion, that we would need to do lookup on partial keys ....

- Jasmeet April 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Trie can also be optimized by not having nodes with degree==2, merged into single node.

- Messi April 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As we always want our phonebook to be sorted in mobile. Binary Search Tree would be the best options. Like we save some memory of sorting when user queries for the result.

- Explorer April 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes a binary search tree would be more efficient

- jack.watermelon April 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How will one store in a BST???
Also order can be maintained in a trie as well.

- A May 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Trie is much efficient for this problem. Names can be stored in trie with the phone numbers as satellite data at the end of names. An even better ds will be ternary search tree, it saves memory as compared to trie. So for very large phone book, ternary search tree will give best efficiency.

- Ankul August 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Patricia tree is the ideal trie DS for any kind of string operation. It uses bit index based on the difference in bits on new string with existing string and stores the new string in the differential index. This results in natural compression of trie nodes resulting in efficient search operation which is what is needed for Phone note book.

An easier but not so efficient ds is building tree with alphabet as index.

typedef struct trie_ {
struct trie_ *alpha[MAX_ALPH];
bool leaf;
} trie_td;

- Anonymous April 01, 2017 | 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