181. Write a function that output the size of highest .......
Microsoft Interview Questions and Answers
(Continued from previous question...)
181. Write a function that output the size of highest .......
Question:
Write a function that output the size of highest sub square matrix of 1s in matrix of 0s and 1s
For ex:
0 1
0 0 output 1
0 0 0
0 1 1
0 1 1 output 2
maybe an answer:
int submatrix(int mat[][MAX],int order,int row,int col)
{
int m=0,z=0,i,j;
while(z <= col - order)
{
while(m <= row - order)
{
for(i=z;i<order + z;i++)
{
for(j = m;j<order + m;j++)
{
cout <<mat[i][j];
if(mat[i][j] != 1)
break;
}
if(j != order + m)
break;
cout << endl;
}
if(j == order + m && i == order + z)
return 1;
m++;
}
m=0;
z++;
}
return -1;
}
(Continued on next question...)
Other Interview Questions
|