Microsoft Interview Question for Software Engineer in Tests






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

SM()
	i1 = 0, i2 = n, j1 = 0, j2 = m
	i = 0, j=0
	while(i2 >=n/2 || j2 >= m/2 || i1 < n/2 || i2 <=n/2)
		for each j from j1 to j2
			print a[i][j]
		i1 = i1+1
		j = j2
		
		for each i from i1 to i2
			print a[i][j]
		j2 = j2-1
		i = i2
		
		for each j from j2 to j1
			print a[i][j]
		i2 = i2-1
		j = j1
		
		for each i from i2 to i1
			print a[i][j]
		j1 = j1 +1
		i = i1

- Prateek Caire September 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
main()
{
int a[20][20],i,j,n,m,p,q,k=0;
printf("\n Enter Order Of matrix");
scanf("%d%d",&m,&n);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);

p=m;
q=n;
i=j=1;

while(k<p*q)
{
for(;j<=n&&k<p*q;j++)
{
printf("%d ",a[i][j]);
k++;
}
j--;
i++;
for(;i<=m && k<p*q;i++)
{
printf("%d ",a[i][j]);
k++;
}
i--;
j--;
for(;j>=i-m+1 && k<p*q;j--)
{
printf("%d ",a[i][j]);
k++;
}
j++;
i--;
for(;i>1 && k<p*q;i--)
{
printf("%d ",a[i][j]);
k++;
}
if(k<p*q)
{
j++;
i++;
n--;
m--;
}
}
}

- neeraj.goyal90 November 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public void spiralMatrix(int mat[][],int r,int c){

int r1=0,r2=r-1,c1=0,c2=c-1;

int visit=r*c,k=0;


while(k<visit){

for(int i=c1;i<=c2;i++){

System.out.println(mat[c1][i]);

k++;
}

for(int i=(r1+1);i<=r2;i++){

System.out.println(mat[i][r2]);

k++;
}

for(int i=c2-1;i>=c1;i--){


System.out.println(mat[c2][i]);

k++;
}

for(int i=(r2-1);i>=(r1+1);i--){


System.out.println(mat[i][r1]);

k++;
}


c1++;
c2--;
r1++;
r2--;
}


}

- vijay.lokhande.in May 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

kkkkkkkkk

- ghkjhhjl March 20, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>

main()
{
int m,n,i,j,left,right,top,down;
printf ("enter m  :  ");
scanf("%d",&m);
printf ("enter n  :  ");
scanf("%d",&n);
int **a;
a=(int**)malloc(m*sizeof(int*));
for (i=0;i<m;i++)
	a[i]=(int*)malloc(n*sizeof(int));
	
printf ("enter the elements of matrix one by one (press enter after each one)\n");	
	
for (i=0;i<m;i++)
	{	for (j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	}
	
printf ("you have entered the matrix\n");		
for (i=0;i<m;i++)
	{	for (j=0;j<n;j++)
			printf("%6d ",a[i][j]);
		printf ("\n");	
	}	

left=0;
right=n;
top=0;
down=m;

printf ("\n");
printf ("The spiral form is : ");
printf ("\n");
	
while (1)	
	{   
	

	
		for (j=left;j<right;j++)
			printf ("%d ",a[top][j]);
         top++;
		if (left>right-1 || top>down-1) 
			break;
			
			
		for (i=top;i<down;i++) 
			printf ("%d ",a[i][right-1]);
		right--;
		if (left>right-1 || top>down-1) 
			break;
			
		for (j=right-1;j>=left;j--)
			printf ("%d ",a[down-1][j]);
		down--;
		if (left>right-1 || top>down-1) 
			break;
			
			
		for (i=down-1;i>=top;i--) 
			printf ("%d ",a[i][left]);
		left++;
		if (left>right-1 || top>down-1) 
			break;
		


	}	
printf ("\n");			
}

- Anonymous August 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can do like this as well in recursive manner :

public static void printSpiralRun(int mat[][], int m, int n) {

printSpiral(mat, m, n, 0);
}

public static void printSpiral(int mat[][], int m, int n, int k) {
if ((m <= 0) || (n <= 0))
return;

if (m == 1) {
for (int j = 0; j < n; j++)
System.out.print(mat[k][k + j] + " ");
return;
}

if (n == 1) {
for (int i = 0; i < m; i++)
System.out.print(mat[k + i][k] + " ");
return;
}

// print from top left
for (int j = 0; j < n - 1; j++)
System.out.print(mat[k][k + j] + " ");

// print from top right
for (int i = 0; i < m - 1; i++)
System.out.print(mat[k + i][k + n - 1] + " ");

// print from bottom right
for (int j = 0; j < n - 1; j++)
System.out.print(mat[k + m - 1][k + n - 1 - j] + " ");

// print from bottom left
for (int i = 0; i < m - 1; i++)
System.out.print(mat[k + m - 1 - i][k] + " ");

printSpiral(mat, m - 2, n - 2, k + 1);
}

- ashishtiwaribng November 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

make it simple

- kavin prabu February 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
int main()
{
int a[50][50],i,j,r,c;
printf("enter the number of rows and columns");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
printf("enter %drow elements\n",i);
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
int l=0,m=r-1,p=0,q=c-1;
while(l<=m && p<=q)
{
for(i=p;i<=q;i++)
{
printf("%d",a[l][i]);
}
for(i=l+1;i<=m;i++)
{
printf("%d",a[i][q]);
}

{
for(i=q-1;i>=p;i--)
{
printf("%d",a[m][i]);
}

{
for(i=m-1;i>l;i--)
{
printf("%d",a[i][p]);
}
}
l++;
m--;
p++;
q--;
}
}

}

- viki June 01, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
int main()
{
	int a[50][50],i,j,r,c;
	printf("enter the number of rows and columns");
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++)
	{
		printf("enter %drow elements\n",i);
		for(j=0;j<c;j++)
		{
		scanf("%d",&a[i][j]);
	    }
	}
	int l=0,m=r-1,p=0,q=c-1;
	while(l<=m && p<=q)
	{
		for(i=p;i<=q;i++)
		{
			printf("%d",a[l][i]);
		}
		for(i=l+1;i<=m;i++)
		{
			printf("%d",a[i][q]);
		}
		
		{
		for(i=q-1;i>=p;i--)
		{
			printf("%d",a[m][i]);
		}
		
		{
			for(i=m-1;i>l;i--)
			{
				printf("%d",a[i][p]);
			}
		}
		l++;
		m--;
		p++;
		q--;
	}
}
	
}

- viki June 01, 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