Microsoft Interview Question
Software Engineer in TestsMore outputs and many more
Y7Y Y2Y Y2Y Y3Y
413 685 314 547
685 413 586 261
Y2Y Y7Y Y7Y Y8Y
The logic behind this is,
Start filling any number in first row. say Y5Y. and proceed further with the given rule
b[k] ={1,2,3,4,5,6,7,8}
m = 3
n = 3
V()
for each i from 0 to n-1
for each j from 0 to m-1
if((a[i][j] != a[i+1][j] +/- 1) && (a[i][j] != a[i][j+1] +/- 1) && (a[i][j] != a[i-1][j] +/- 1) && (a[i][j] != a[i][j-1] +/- 1))
return true
else
return false
SS(k)
if(k == 7)
if(V())
for each i from 0 to n-1
for each j from o to m-1
print a[i][j]
for each i from 0 to n-1
for each i from 0 to m-1
if(!((i == 0 && j ==0 ) || (i == 0 && j ==2) || (i == 2 && j ==0) || (i == 2 && j ==2)))
a[i][j] = b[k]
SS(k+1)
b[k] ={1,2,3,4,5,6,7,8}
m = 3
n = 3
V()
for each i from 0 to n-1
for each j from 0 to m-1
if((a[i][j] != a[i+1][j] +/- 1) && (a[i][j] != a[i][j+1] +/- 1) && (a[i][j] != a[i-1][j] +/- 1) && (a[i][j] != a[i][j-1] +/- 1))
return true
else
return false
SS(k)
if(k == 7)
if(V())
for each i from 0 to n-1
for each j from o to m-1
print a[i][j]
return
for each i from 0 to n-1
for each i from 0 to m-1
if(!((i == 0 && j ==0 ) || (i == 0 && j ==2) || (i == 2 && j ==0) || (i == 2 && j ==2)))
a[i][j] = b[k]
SS(k+1)
It could be similar to 8 queens problem.
- anonymous July 01, 2012