Microsoft Interview Question for Software Engineer in Tests






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

Most efficient algorithm for sub-string search

http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm

- Houston October 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Start with 2 pointers, p1 pointing to first character in S1 and p2 to first character in S2. Move p2 till *p2 is equal to *p1. After that, move each pointer by 1 position. As soon as *p1!=*p2, move p1 back to the start. Repeat above till you reach the end of S2.
This will be done in O(n) time

- Metta October 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will take O(m*n) time..... where m and n are lengths of s1 and s2.

- shail June 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool IsSubstring(char * search , char * in)
{

int searchlen= strlen (search), inlen= strlen(in);
int it , innerit;
int begin=0;
assert(search !=NULL && in != NULL);
assert(searchlen >0 && searchlen <= inlen);

for(it = 0; it< inlen-searchlen; it++)
{
//if first char of search matches with the current char
if(search[begin] ==in[it])
{
innerit= it+1;
begin++;
//proceed further check for the remaining
while(begin < searchlen)
{
// if any mismatch is found break out of it
if(in[innerit] != search[begin])
{
begin = 0;
break;
}
innerit++;
begin++;
}
// if match was found following condition will be true
if(begin == searchlen)
{
return true;
}
}
}
return false;
}// end of IsSubstring

- Bhagyashree :o) October 18, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Knuth Morris is a good algorithm but suffix trees is even a better algorithm if you are going to find a match for many substrings. Knuth Morris processes the substring while suffix trees process the main string.

- Gaurav January 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Knuth Morris is a good algorithm but suffix trees is even a better algorithm if you are going to find a match for many substrings. Knuth Morris processes the substring while suffix trees process the main string.

Complexity:
Knuth Morris: O(n|S| + Si | pi |) time for n queries.

Suffix trees: O(|S| + Si | pi |) time for n queries.

Hence suffix trees is a better option

- Gaurav January 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I cant believe you would mention suffix trees in the interview and get away coding it. I think it very tough to code during the interview. So wisely onely should not give a solution using suffix trees.

- peace November 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i believe , no one will ask you to write code if it is very tough in limited time , so there is nothing wrong in saying suffix tree and you should be in a position to atleast try coding for suffix tree in that limited time in case interviewer would like to know your coding skills , who knows , his intention might be to know from you whether you are aware of "suffix tree " concept or not , if you are not revealing abt it , then he might even think you didnt even know the name "suffix tree " ..

- Anonymous November 23, 2009 | 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