Amazon Interview Question for Software Engineer / Developers






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

Well, probably this is an algorithm probelm instead of a design problem. Convert to an directed graph, every word as a node and any two words with only one character different have one edge with weight 1 connecting them. From the source node to the target node, it's like find a path between them, then you can use Dijkstra's algorithm or Dp and the path is the answer.

- ilikedeal February 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the real question is here is, how will you construct such a graph? It is not obvious how to get all the words in a dictionary that differ from the present word by only one character.

Even given such words, it is not obvious how to design an algorithm that can judge which word will take it closer to the target word.

- Anonymous May 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

will edit distance algorithm solve the problem ?

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

Edit distance just gives you the minimum cost of transforming
one word to the other, the intermediate words need not be valid
words in the process. Here in this problem, the intermediate words
should be valid words, so edit distance directly may not solve the problem.

- beginner September 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Look at careercup.com/question?id=14722757

- Vikas October 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

This works:

public static int levenshteinDistance(String src, String target){

int srcLen = src.length();
int targetLen = target.length();
int cost = 0;

if(srcLen <= 0 || targetLen <= 0){
return 0;
}

if(src.charAt(srcLen-1) != target.charAt(targetLen-1)){
cost = 1;
}

if(srcLen == 0){
return targetLen;
}else if(targetLen == 0){
return srcLen;
}else{
return Math.min(Math.min(levenshteinDistance(src.substring(0, srcLen-1), target) + 1,
levenshteinDistance(src, target.substring(0, targetLen - 1)) + 1),
levenshteinDistance(src.substring(0, srcLen - 1), target.substring(0, targetLen - 1)) + cost);
}


}

- A January 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

example: turn DAMP to LIMB thru ... DAMP -> LAMP -> LIMP -> LIMB ... construct a binary tree to store all meaningful words, then do a BST...that shud do it...

- game. February 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We have a set of words from the dictionary that we can look up.

We first compute the levenshtein distance between the two candidate words and save it in a temp variable.

1.
Then choose a list of words from the dictionary of the same length as the destination word and such that there is only one character change in the source word. ( also read as the levenshtein distance is 1 ).

for e.g. damp -> limbs

damp -> damps -> lamps -> limps -> limbs

So now we have listOfWords[] such that they differ only by one character in the source.

2.
Now from this listOfWords[], compute the levenshtein distance of listOfWords[i] and destination word and choose only those set of words which have the least distance from the destination word.

Repeat steps 1 & 2 till we have the destination word, in course of which we maintain the words chosen to reach this destination word.

- fragzilla March 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One of the way to do could be
1. construct a DAWG (directed acyclic word graph) of all meaningful word formed by first letter to source word ateast equivalent to final word.
As given only one character change at a time is allowed thus there should exist a path where if in above constructed DAWG if the initial word is replaced with first letter of final word it would lead to final word.

For exam:
head -> tail

transformation may will include: head->heal->hell->hall->hail->tail

DAWG for head includes: head,heal, hell, hall, hail, etc.

thus if we traverse DAWG comparing all letters after first letter, we should get a path to reach hail (i.e. tail when h is replaced by tail).

Wil this work?

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

See the "EDIT-DISTANCE PROBLEM" in wiki

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

how abt using Tries?

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

cann you give some example, question is not clear

- Anonymous February 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote
- chetak February 23, 2010 | 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