Amazon Interview Question for Software Engineer / Developers






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

I don't know for sure. But I have some vague feeling that variable length trie would do the task. Like start for each row scan character by character and traverse the nodes and then if the prefix is a word then it will be found in a leaf and so on.

- Anonymous January 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Generate(string word)
{
if(isWord(word))
print word;

for(int i =0; i< N; i++)
{
for(int j=0; j<N; J++)
{
if(IsPrefix(word, a[i][j])
Generate(word + a[i][j]);
}
}


word = string.empty ;
for(int i =0; i< N; i++)
{
for(int j=0; j<N; J++)
{
if(i==j==0) continue;
Generate(word + a[i][j]);
}
}


}


Generate (a[0][0]);

- Anonymous January 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printWord(string str, int row, int col)
{
if (isWord(str))
{
print str;
}

char nextLetter = '';
if (col < N-1){
nextLetter = a[row][++col];
}else if (row < N-1) {
col = 0;
nextLetter = a[++row][col];
}

if (nextLetter == '')
{
return;
}

str += nextLetter;
if (isPrefix(str)) {
printWord(str, row, col);
}
}


void main(...)
{

for (int i=0; i<N; i++)
{
for (int j=0; j<N; j++)
{
printWord(a[i][j], i, j);
}
}

}

- yokuki January 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printWord(char[][] a, String str, boolean[][] flags) {
if (isWord(str)) {
System.out.println(str);
}

if (!isPrefix(str)) {
return;
}

char nextLetter = ' ';

for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
if (!flags[i][j]) {
nextLetter = a[i][j];
flags[i][j] = true;
printWord(a, str + nextLetter, t, flags);
flags[i][j] = false;
}
}
}
}

public static void main(String[] args) {
// initialization
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
flags[i][j] = true;
printWord(a, a[i][j] + "", flags);
flags[i][j] = false;
}
}
}

- w1uo0 April 08, 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