Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

You'd want some kind of tree structure for querying by geographic region. Since you can query by regions like state or drill down to state + city + street, a hierarchical representation like a tree is appropriate. Give the tree a node for each state, give each state node a child node for each city, give each city node a child node for each street, and then give each street a Set of Names. That way, it's very easy to satisfy any queries of the form "given any State or State + City or State + City + Street return all names". Just go to the appropriate level of the tree and recursively traverse all the subtrees from there, getting the union of all the Sets of names encountered (you don't have to check for duplicates since the sets are disjoint).


For querying by name, a hashtable, tree, or B-tree if you're trying to save space is reasonable. This datastructure would establish an efficient map between names and records (a record contains the name, state, city, and street; it's basically a database row).

- eugene.yarovoi April 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

See Wiki page for database index and its implementations

- Anonymous April 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think, we can use either k-d tree or B+ tree

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

B Tree is good... kd tree is not the right DS to use ....as it is used for distances of some sort..primarily physical distances.

- Tintin April 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@eugene assuming the question is asking us to solve scenarios that database implements, I think B trees or trees shouldn't contain the actual data but pointers to records.

- Anonymous April 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

implements this tree using hashMap might also reduce the traversal time through the tree.

- papa April 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The solution can be archived using R-trees

- Anonymous April 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The solution can be achived using R-trees

- Anonymous April 25, 2012 | 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