Interview Question for Software Engineer in Tests


Country: United States
Interview Type: Phone Interview




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

Use pointer to pointing to the start of two string. Compare if match. If yes, move the pointer to PATTERN together with pointer to INPUT. If match not found, reset pointer to PATTERN to the begin.

- peter tang October 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

first of all, you didnt cover wildchar which can match multiple chars. Then what about this
input= aaaabc
pattern = aaabc

- Lucas November 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For wildchar case, don't move the pointer to the PATTERN.
For the case of aaaabc and aaabc.
The first around aaaa doesn't match aaab
The second around aaabc matches aaabc, then reutrn 1 (0-based index)

- peter tang November 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This change be done in o(n) by modifying Knuth-Morris-Pratt algorithm. The small modification is, if index i in pattern string is *, make next[i+1]=i and i is also the min of next[] for index > i.

- buffalo October 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let pattern(array, p[]) be of length M and given string(array, str[]) be of length N. Now,
int findMatchingIndex(char*str, char*p)
{
int i=0, j=0;
for(i=0;i<=N-M+1;i++)
{
if(str[i]==p[i])
{
int xored=1;
for(int j=0;j<M;j++)
{
xored *= str[i+j] ^ p[j];
if(xored==0)
return i; //index of first match
}
}
}
return -1; //not found
}

- ashu1.220791 November 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

care to share the psudo code?

- Lucas November 01, 2012 | 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