Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

stackoverflow.com/questions/746082/how-to-find-list-of-possible-words-from-a-letter-matrix-boggle-solver

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

Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

do u want to read all the words from the dictionary which contains "all the possible English words" i don't think this will be efficient.

- hitman February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But I guess the person has already mentioned that he has a dictionary containing all the words .... so I guess we need to take the words from there itself

- yasha.khandelwal02 February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But I guess the person has already mentioned that he has a dictionary containing all the words .... so I guess we need to take the words from there itself

- yasha.khandelwal02 February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But I guess the person has already mentioned that he has a dictionary containing all the words .... so I guess we need to take the words from there itself

- yasha.khandelwal02 February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But I guess the person has already mentioned that he has a dictionary containing all the words .... so I guess we need to take the words from there itself

- yasha.khandelwal02 February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But I guess the person has already mentioned that he has a dictionary containing all the words .... so I guess we need to take the words from there itself

- yasha.khandelwal02 February 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Read a word from the dictionary file.
2. Insert it into a prefix tree data structure in memory.
3. Repeat steps 1-2 until all words in the dictionary have been inserted into the prefix tree.
4. Using backtracking, search the board for words.
5. If a word is found and it contains 3 or more letters, search the prefix tree for the word.
6. If searching was *not* successful in the previous step, return from this branch of the backtracking stage. (There is no point to continue searching in this branch, nothing in the dictionary as the prefix tree says).
7. If searching was successful in step 5, continue searching by constructing more words along this branch of backtracking and stop when the leaf node has been reached in the prefix tree. (at that point there is nothing more to search).
8. Repeat steps 4-7 as long as there are more words to search in the backtracking.

- yasha.khandelwal02 February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 build a ac-automation according to the dictionary.
2 query matrix[i][1..4] ,matrix[1..4][i],matrix[4..1][i],matrix[i][4..1]
we can get the answer.

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

This is basically a permutation problem. Hence the total number of possible words is found by..

16p1 + 16p2 + 16p3 +................................................ + 16p15 + 16!

However this solution results in many combinations which are not possible by joining characters in the adjoining cells.

- Vijay Rajanna February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

FW: find a word 's'
IW: Is a word in dictionary Trie
BS: Boggle search
v[][] = if particular cell visited earlier (0 or 1)

FW(i, j, s)
	if(IW(s))
		print the s and the meaning from dictionary
	if(i-1 >= 0 && !v[i-1][j])
		v[i-1][j] = 1
		FW(i-1, j, s+a[i-1][j])
	if(i+1 <= m-1 && !v[i+1][j])
		v[i+1][j] = 1
		FW(i+1, j, s+a[i+1][j])
	if(j-1 <=0 && !v[i][j-1])
		v[i][j-1] = 1
		FW(i, j-1, s+a[i][j-1])
	if(j+1 <= n-1 && !v[i][j+1])
		v[i][j+1] = 1
		FW(i, j+1, s+a[i][j+1])

BS()
	for each i from 0 to m-1
		for each j from 0 to n-1
			v[i][j] = {0}
			FW(i,j, a[i][j])

- Prateek Caire February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

seems BS() is incorrect,
before searching from each position (i, j), v[][] should be initialized to zero, not only v[i][j]

- StartFromNeg1 February 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what if we do DFS starting from a character and saving the string till then and look for the word in dictionary ?

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

@original poster ...can you please elaborate ..what is meant by "connecting the neighboring cells." ??? say for a 2X2 matrix

a m o k
c t l p
i s w q
d k s p ......can we use "a c t m " from the upper left corner as a word ?? ,,can a rearrange these letters like "c a t m " ?? or is the order determined by D[0][0] D[0][1] D[1][0] D[1][1] ????

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

@original poster ...can you please elaborate ..what is meant by "connecting the neighboring cells." ??? say for a 2X2 matrix

a m o k
c t l p
i s w q
d k s p ......can we use "a c t m " from the upper left corner as a word ?? ,,can a rearrange these letters like "c a t m " ?? or is the order determined by D[0][0] D[0][1] D[1][0] D[1][1] ????

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

I am trying to use recursion starting with each letter in the matrix and building all the words through their neighbors until the word length doesn't go beyond the threshold (that is the longest word in the dictionary)



void allwords(char ar[][],vector<string> dic, int thresh)
{

vector<string> list
for(int row=0;row<3;row++)
for(int col=0;col<3;col++)
findWords(ar[][],row,col,ar[row][col],list,thresh,dic);


// remove duplicates fromt the list if any

sort(list.begin(),list.end());
list.erase(unique(list.being(),list.end()),list.end());



}


findWords(char ar[][],int row,int col,string word,vector<string> list,int thresh, vector<string> dic)
{
if(word.length>thresh)
return;

word=word+ar[row][col];
vector<string>::iterator it;
it= find(dic.begin(),dic.end(),word);

if(*it!=dic.end())
list.push_back(word);


// Find all possibilties with the top neighbor

if(row>0)
findWords(ar,row-1,col,word,list,thresh,dic);

if(col<3)
findWords(ar,row,col+1,word,list,thresh,dic);


if(row<3)
findWords(ar,row+1,col,word,list,thresh,dic);

if(col>0)
findWords(ar,row,col-1,word,list,thresh,dic);



// If diagonal nieghbors too has to be included

// Diagonally top right
if(row>0 &&col<3)
findWords(ar,row-1,col+1,word,list,thresh,dic);

if(row<3 && col<3)
findWords(ar,row+1,col+1,word,list,thresh,dic);


if(row>0 && col>0)
findWords(ar,row-1,col-1,word,list,thresh,dic);


if(row<3 && col>0)

findWords(ar,row+1,col-1,word,list,thresh,dic);
}

please mail me if you there's anything wrong in this method c.operatingsystems@gmail.com

- NarayanaMetuku March 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int visit[N][N];
set<string> ans;
dfs(int x, int y, string& prefix)
{
        if (x < 0 || y > 0 || x == N || y == N) return ;
        visit[x][y] = 1; prefix.push_back(a[x][y]);
        if (dict.contains(prefix)) ans.push_back(prefix); 
        for (int i=0; i < 8; i++)
                 dfs(x+X[i], y+Y[i], prefix);
        prefix.pop_back();
        
}

for (int i=0; i < n; i++)
      for (int j=0; j < n; j++)
                  dfs(i, j, string("")) ;  // start the root

- Anonymous August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

// sorry, some minor bugs fixed

int visit[N][N];
set<string> ans;
// possible movies, all up, down, left, right, and diagonals allowed
const int X[] = {-1, 1, -1, 1, 0, 1, -1, 0 }; 
const int Y[] = {-1,  1, 1,  -1, 1, 0, 0, -1 };
 
void dfs(int x, int y, string& prefix)
{
        if (x < 0 || y > 0 || x == N || y == N) return ;
        
        visit[x][y] = 1; prefix.push_back(a[x][y]);
        if (dict.contains(prefix)) 
                       ans.push_back(prefix); 
        for (int i=0; i < 8; i++)
                 dfs(x+X[i], y+Y[i], prefix);
        visit[x][y] = 0;
        prefix.pop_back();
        
}
// inside main 


for (int i=0; i < n; i++)
      for (int j=0; j < n; j++)
                  dfs(i, j, string("")) ;  // start the root

- Anonymous August 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

int visit[N][N];
set<string> ans;
// possible movies, all up, down, left, right, and diagonals allowed
const int X[] = {-1, 1, -1, 1, 0, 1, -1, 0 }; 
const int Y[] = {-1,  1, 1,  -1, 1, 0, 0, -1 };
 
void dfs(int x, int y, string& prefix)
{
        if (x < 0 || y > 0 || x == N || y == N || visit[x][y]) return ;
        
        visit[x][y] = 1; prefix.push_back(a[x][y]);
        if (dict.contains(prefix)) 
                       ans.push_back(prefix); 
        for (int i=0; i < 8; i++)
                 dfs(x+X[i], y+Y[i], prefix);
        visit[x][y] = 0;
        prefix.pop_back();
        
}
// inside main 


for (int i=0; i < n; i++)
      for (int j=0; j < n; j++)
                  dfs(i, j, string("")) ;  // start the root

- Anonymous August 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think this in the blow line x > 0 instead of x < 0
if (x < 0 || y > 0 || x == N || y == N || visit[x][y]) return ;

- atd August 07, 2013 | Flag


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