Microsoft Interview Question for SDE-2s


Team: STB and MVO
Country: India
Interview Type: In-Person




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

Standard pattern matching problem. Use Rabin Karp or KMP algorithm.

- Anonymous April 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use kmp

- alex April 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Naive implementation. When in doubt just brute

def isMatch(pattern,text):
    i=0
    j=0
    while(i < len(text)):
        while j<len(pattern) and pattern[j] == text[i+j]:
            j+=1
            if j==len(pattern):
                return True
        j=0
        i+=1
    return False

- antonydeepak April 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

List<int> IsMatch ( char[] Text, char[] P)
{
List<int> indicesList = new List<>;
a = Text.Length;
b = P.Length;
int checkSumTemp = 0;
int checkSumP = 0;
for(int i = 0; i< b; i++)
{ checkSumTemp += (int)Text[i];
checkSumP += (int)P[i];
}
for(int i = 0; i<=a-b;i++)
{
if(checkSumTemp == checkSumP)
{
for(int j = i; j<i+b; j++)
{
if(Text[j]!=P[j-i]) break;
}
if ( j==i+b )
{
indicesList.Add(i);
}
}
checkSumTemp -= Text[i];
checkSumTemp += Text[i+b];
}
return indicesList;
}

- SJ June 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String pattern = "AAB";
		String text = "AACBAABDJHAAB AAB";

		int patternLength = pattern.length();
		int startIndex = 0;

		for (int textIndex = 0; textIndex < text.length(); textIndex++) {

			if (textIndex + patternLength <= text.length()) {
				String subString = text.substring(textIndex, textIndex
						+ patternLength);
				if (pattern.equalsIgnoreCase(subString)) {
					System.out.println(textIndex);
				}
			}
		}

- Sumit November 18, 2013 | 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