Microsoft Interview Question for SDE-2s


Country: India




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

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
int x;
int y;
}node;

int fun(node* arr[])
{
int i;
int col=1;
int row = 1;

for(i=1;i<3;i++)
{
if(arr[0]->x!=arr[i]->x)
{
row= 0;
break;
}
}

for(i=1;i<3;i++)
{
if(arr[0]->y!=arr[i]->y)
{
col= 0;
break;
}
}

if(col==1&&row==1)
return 3;
else if(col==1)
return 2;
else if(row==1)
return 1;
else
return 0;
}
int main (void)
{
int i,x,y;
node* arr[4];
for(i=0;i<4;i++)
{
scanf("%d%d",&x,&y);

node* temp=(node*)malloc(sizeof(node));
temp->x= x;
temp->y=y;
arr[i]=temp;
}
fun(arr);
return 0;
}

- chunmun August 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
int x;
int y;
}node;

int fun(node* arr[])
{
int i;
int col=1;
int row = 1;

for(i=1;i<3;i++)
{
if(arr[0]->x!=arr[i]->x)
{
row= 0;
break;
}
}

for(i=1;i<3;i++)
{
if(arr[0]->y!=arr[i]->y)
{
col= 0;
break;
}
}

if(col==1&&row==1)
return 3;
else if(col==1)
return 2;
else if(row==1)
return 1;
else
return 0;
}
int main (void)
{
int i,x,y;
node* arr[4];
for(i=0;i<4;i++)
{
scanf("%d%d",&x,&y);

node* temp=(node*)malloc(sizeof(node));
temp->x= x;
temp->y=y;
arr[i]=temp;
}
fun(arr);
return 0;
}

- chunmun August 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public enum PointsState
    {
        None,
        Row,
        Column,
        Diagonal
    }
    public class Point
    {
        public int X { get; set; }
        public int Y { get; set; }
    }

    public class PointChecker
    {
        public static PointsState GetPointsState (IList <Point> points)
        {
            if (points.Count < 2)
                return PointsState.None;

            var firstPoint = points[0];

            bool sameX = true;
            bool sameY = true;
            bool sameDiagonal = true;

            for (var i = 1; i < points.Count; i++)
            {
                if (points [i].X != firstPoint.X)
                    sameX = false;

                if (points [i].Y != firstPoint.Y)
                    sameY = false;

                // check if diagonal!

                if (firstPoint.X * points [i].Y != firstPoint.Y * points [i].X)
                    sameDiagonal = false;
            }

            if (sameX)
                return PointsState.Row;
            if (sameY)
                return PointsState.Column;
            if (sameDiagonal)
                return PointsState.Diagonal;
            return PointsState.None;
        }
    }

- aurelian.lica October 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You missed the 'consecutive' part i guess.

- nir March 28, 2018 | 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