Microsoft Interview Question for Software Engineer in Tests






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

I think , all solutions are wrong .
Correct Idea is :
1) Find convex hull of points
2) Print it
3)Remove these points from current set of points
4) Do steps 1,2,3 while number of points > 0

- MICROSOFTian August 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please throw your ideas. I am waiting if someone could throw some light on this.

- Sadineni.Venkat February 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you sure like the word throw don't you moron?

- Anonymous September 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous : You better contribute to the community or shut your mouth!

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

This is similar to traversing a martix in spiral form. I was asked this questions for my Facebook interview. Solution is as follows:

#include <stdio.h>

#define N 5
#define M 3

int min(int a, int b)
{
return a < b ? a : b;

}

void spiral(int mat[M][N])
{
int n = N, d = +1, i = 0, j = -1;
int s, segl = N + M - 1;
for (s = 0; s < min(N, M); s++, d = -d, segl -= 2, n--) {
int c, *ip = &j;
for (c = 0; c < segl; c++) {
if (c == n)
ip = &i;
*ip += d;
printf("%3d", mat[i][j]);
}
}

}

I got this solution from :
http://discuss.joelonsoftware.com/default.asp?interview.11.575151.3

Credits to Sandeep NL who got it from C groups.

- Anonymous February 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awsome Code .... Thnx for sharing ....

- Fcker_24X7 November 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is similar to traversing a martix in spiral form. I was asked this questions for my Facebook interview. Solution is as follows:

#include <stdio.h>

#define N 5
#define M 3

int min(int a, int b)
{
return a < b ? a : b;

}

void spiral(int mat[M][N])
{
int n = N, d = +1, i = 0, j = -1;
int s, segl = N + M - 1;
for (s = 0; s < min(N, M); s++, d = -d, segl -= 2, n--) {
int c, *ip = &j;
for (c = 0; c < segl; c++) {
if (c == n)
ip = &i;
*ip += d;
printf("%3d", mat[i][j]);
}
}

}

I got this solution from :
http://discuss.joelonsoftware.com/default.asp?interview.11.575151.3

Credits to Sandeep NL who got it from C groups.

- Anonymous February 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Not sure what the post about Matrix is about, seem irrelevant to the problem, which I interpreted as, "You are given n 2D points in the plane, give a sequence of those n points, P1, P2, ..., Pn, such that when you go from P1 to P2 to P3 etc, if forms a 'spiral'".

The following approach might work:

Take convex hull repeatedly, forming convex shells. Start with the innermost shell and spiral outward.

This should be worst case O(n^2 logn). (Finding convex hull is O(nlogn)).

- T March 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. Find the distance of all the points to the origin (0,0).
2. Sort them in increasing order.
3. You should be able to form a spiral joining these points in that order. (say moving clockwise)

- sundarvenkat2 April 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sundarvenkat2 is close. But, the correct answer is.

1. Find the distance of all points to the mean.
2. Sort them in increasing order
3. You should be able to form a spiral joining these points in that order. (say moving clockwise)

- S May 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, both sundarvenkat2 and you have got it wrong.


Your algorithm can give a 'spiral' which will intersect itself.

- LOLEr September 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a Fibonacci series question. To plot every new point, use sum of distances of last 2 points from a fixed center.

- Nix September 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL

- LOLer September 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nix: will you mind spending 10 seconds to re-read the question and understand what exactly has been asked. you moron, people like you are wasting this great website.

- xin hu October 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rather than anything else, the question deals with finding the slope of the points such that no point les above or below that line.

4 points need to be maintained always, these would be Max X, Min X, Max Y, Min Y.

We check none above if line is between Min X and Max Y or Max Y and Min X and we check none below otherwise.

This requirs sorting on the basis of two variables, Once n X and other time on Y.

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

1. sort the vertices on X.. for same X sort them on Y...
2. find MaxX, MaxY, MinX, MinY...
3. create a matrix of dimensions MaxX-Minx, MaxY-Miny..
4. store the points in the matrix
5. print the matrix in spiral fashion...

enjoy life king size

- Anonymous November 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

So suppose we have sorted the vertices on X and Y...
Store them in 2-d array..

void MatrixHelix(int mat[][N], int M){

int round;
for ( round = 0; round < min(M,N)/2, round++){

int i = j = round;
for ( ;j < N - round ; j++)
   print ( mat[i][j]);

for ( i = round+1; i< M-round; i++ )
   print ( mat[i][j]);

for ( j = j -1 ; j >= round; j-- )
   print ( mat[i][j])

for ( i = i -1 ; i >= round ; i--)
   print ( mat[i][j])
}

if ( M > N)
 for (int i = round, j = round ; i < M ; i++ ) 
    print ( mat[i][j]);
else if ( M < N)
 for (int j = round, i = round ; j < M ; j++ ) 
    print ( mat[i][j]);
}

- Anonymous November 10, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This answer seems to be correct ..... But will use a lot of extra space...

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

The question doesn't seem to be clear. It could be interpreted in more than one way. Most importantly, I don't understand : What should be the output of the algorithm? (A spiral printed on screen or a particular order of vertices or boolean value denoted possibility of a spiral ...)

- Sam January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find convex hull
The find convex hull off remaining points recursively...
Linking up convex hulls is trivial

The matrix approach is crap...

- Don February 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hw abt sort co-ordinates in 1d matrix on x axis basis and if it matches then compare y.
After that, print it using following loop:
for(int i=0, j=n/4, k=n-1, l=3n/4-1; i<n/4, j<n/2, k>=3n/4, l>=n/2; i++, j++, k--, l--)
{
arr[i]
arr[j]
arr[k]
arr[l]
}
NOTE: I considered case where no of points is multiple of 4 :)

- Di 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