Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Sorry about formatting

List<string> FindAllWords(char[,] mat, string filePath)
{
    bool[,] used = new bool[mat.length,mat.length];
    
    Trie t = new Trie(filePath);
    
    List<string> allWords = new List<string>();
    
    for(int i=0; i<mat.length ; i++)
     for(int j=0; j<mat.length; j++)
     {
         foreach(string str in FindWordsFromLocation(i,j,mat,used,t,""))
         {
             allWords.Add(str);
         }

     }
     
     return allWords ;
}

List<string> FindWordsFromLocation(int i, int j, char[,] mat, bool[,] used, Trie t, string prefix)
{
    if(i<0 || i>mat.length || j<0 || j>mat.length) return null;
    
    if(bool[i,j]==true) return null;
    
     
    List<string> words = new List<string>();
    
    if(t.ContainsWord(prefix))
    {
        words.Add(prefix);
    }
    
    string newPrefix = prefix + mat[i,j];
    used[i,j] = true;
    
    if(t.ContainsPrefix(newPrefix))
    {
        foreach(string str in FindWordsFromLocation(i+1,j,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i-1,j,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i,j+1,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i,j-1,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i+1,j+1,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i+1,j-1,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i-1,j+1,mat,used,t,newPrefix))
            words.Add(str);
        foreach(string str in FindWordsFromLocation(i-1,j-1,mat,used,t,newPrefix))
            words.Add(str);
    }
   
    used[i,j] = false;
    
    return words    
   
}

- Craby January 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

crab on the road

- soni.vashisht January 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{ crab on the road
}

- soni.vashisht January 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{ crab on the road
}

- soni.vashisht January 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use trie tree to implement it

- seek January 18, 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