Funky chess board

what will be output for following test cases ?

3

1 1 1
0 0 0
1 1 1

The output of this test case will be 3


Let me know any test case for which my code fail.

For the test input:
10
1 1 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1
Your code’s output: 7
Expected output: 17

You are considering all the traversals possible on the chess board to obtain the boxes left unvisited. For this question your answer is to be obtained from just one of all the possible traversals.

exactly. This happen only because of wrong interpretion of question.
thanks for figuring out mistake.

1 Like

in this problem i have to move knight only in one direction from current position.
am i right ??

You will move in all directions and backtrack till you find the case where you can traverse maximum blocks.

1 1 1
0 0 0
1 1 1

in above i have doubt,
i think 3rd row in also not part of grid because there is no link ??
am i correct

Technically you are correct
but the Question doesnot put any constraints on it and allows you to include 0’s in path

1 1 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1

logic hit in this test case.
i you see from 1 to 3 row there is link. and from 4 to 10 are separate grid.
from 1 to 3 row only one square grid is unvisited and remain from 4 to 10 there are 16 unvisited
square grid because of there is no link.
Thus over all answer = 17 , is coming.

i found most of problems of coding blocks are ambiguous. They even didn’t properly explain the test cases.

Can’t say much about ambiguity but deciphering the problem by oneself is like 50% problem solved and with each of such problem comes tricks which you will notice on various competitive platforms.For the question to ‘click’ practice is required.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.