Microsoft Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

Make Hash of first array with noc(number off occurences) of each element..
Now go through second array if hash contains element and noc>0, add that element in intersection array.
Time O(n+m)
Space O(n)

- loveCoding January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

A simple way will be using the second array and as u get a common element index it and increment the index..it is O(n2) but no memory complexity

int main()
{
int a[] = {0,1,2,3,1,1,0,1,0,4,5,8,1,2,3};
int b[] = {0,3,4,1,1,2,1,0,2,7,6,5,3,2};
int i,j,index = 0;
int temp;

for(i = 0 ; i < sizeof(a)/sizeof(int) ; i++)
{
for(j = index ; j < sizeof(b)/sizeof(int); j++)
{
if(a[i] == b[j])
{
temp = b[index];
b[index] = b[j];
b[j] = temp;
index++;
break;
}
}
}
for(i = 0; i < index ; i++)
printf("%d ",b[i]);
}

- Vijayanand March 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

A simple way will be using the second array and as u get a common element index it and increment the index..it is O(n2) but no memory complexity

int main()
{
int a[] = {0,1,2,3,1,1,0,1,0,4,5,8,1,2,3};
int b[] = {0,3,4,1,1,2,1,0,2,7,6,5,3,2};
int i,j,index = 0;
int temp;

for(i = 0 ; i < sizeof(a)/sizeof(int) ; i++)
{
for(j = index ; j < sizeof(b)/sizeof(int); j++)
{
if(a[i] == b[j])
{
temp = b[index];
b[index] = b[j];
b[j] = temp;
index++;
break;
}
}
}
for(i = 0; i < index ; i++)
printf("%d ",b[i]);
}

- Vijayanand March 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int a[] = {0,1,2,3,1,1,0,1,0,4,5,8,1,2,3};
int b[] = {0,3,4,1,1,2,1,0,2,7,6,5,3,2};
int i,j,index = 0;
int temp;

for(i = 0 ; i < sizeof(a)/sizeof(int) ; i++)
{
for(j = index ; j < sizeof(b)/sizeof(int); j++)
{
if(a[i] == b[j])
{
temp = b[index];
b[index] = b[j];
b[j] = temp;
index++;
break;
}
}
}
for(i = 0; i < index ; i++)
printf("%d ",b[i]);
}

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

Sort the arrays and walk both the arrays to find intersection. O(nlogn) ( + 2n). space complexity O(1). I am not sure if this is the best solution.

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

sort the arrays
remove duplicates from both the arrays
compare the arrays
if equal, add it to the intersection set

- vasu August 27, 2012 | 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