Amazon Interview Question for Software Engineer / Developers


Team: SDE
Country: India
Interview Type: In-Person




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

use tries for constant lookup in the dictionary

In precompute phase build up an undirected graph where there is an edge between words A and B if we can transform A to B (and vs) by changing only one character. The above trie structure provides pointers to graph nodes for fast lookup.

Now for queries, we build up a matrix A of size N x N where N is the # of words.
s.t. A[i][j] = 1 if we can transform a word 'i' to work 'j' by changing one character at a time.

To build this matrix we execute BFS from each node of the graph and mark all reachable nodes. BFS also gives us the smallest # of steps to transform the words hence the last question is also answered

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

can you paste some example for the above:
suppose length 3 strings are availble in the cache,
ex: abc,bbc two strings in cache,
now given a string 'bbd' - is transformable or not, please let me know

- rider3125 February 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can probably use trie as a data structure here, and the question of "one more API which calculate minimum number of Steps required to transform X to Y" can be solved using the lowest common ancestor to a trie) I am not sure how this works in O(1) though.

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

Union find support this.

- any February 05, 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