Microsoft Interview Question for Software Engineer in Tests






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

1.what if char a and b occurs multiple times, which means there are more than distances between them?
2. it needs to be a to b or could be from b to a?

- Jackie October 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dont understand the question... Can you be bit more explicit?
How do you define distance in the input?

- saurabh.comps November 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actually, I think you can understand this question in another way, which the distance between the most nearest a and b <= distance or not

bool findABWithinDis(string s, char a, char b,int distance)
{
char c;
int firstPos = -1;
if((s.size()>1 )&& (distance < s.size()-2))
{
for(int i=0;i<s.size();i++)
{
if((firstPos > -1)&&(s[i]==c)&&(i-firstPos <=distance))
{
return true;
}
if(s[i] == a)
{
c = b;
firstPos = i;
}
else if(s[i] == b)
{
c = a;
firstPos = i;
}

}
}
return false;
}

and it is O(n).

- Vincent.Y.Guo March 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Poor solution.

- Mahesh March 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Assumptions: Null terminated string

// Test cases. If value of d is way to big then the code will return
// value of d cannot be -ve
// a and b can be same or different
// a and b can contain any values including '\0'

void func(char a,char b,char* str,int dist)
{
char t1,t2;
int flag=-1,count=dist,i=0;

// Distance cannot be less than or 0
if(dist<=0)
return ;


while(i+dist<strlen(str))
{
t1= str[i];
t2= str[i+dist];

if(t1==a)
flag=1;
else if(t1==b)
flag=2;

if(flag==1 && t2== b)
{
printf("Match found\n");
return;
}
else if(flag==2 && t2==a)
{
printf("Match found\n");
return;
}
flag=-1;
i++;
}
}

- abhimanipal May 23, 2010 | 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