Funky chess board

test cases not run…

Hello @dakshi,

Overall logic of your code is correct.
But the way you are using backtracking will result into wrong output.
Correct approach:

Hope, this would help.
Give a like if you are satisfied.

plz point the misktake
i cannot get it …
why the maximum is taken ?
why reintialising the cell with 1…

Hello @dakshi,

To understand the answer to your question, you are required to understand the logic of that code.

LOGIC:

  1. Starting from the (0,0) position, we are going to move to all the possible locations that are possible to visit.
  2. You mark that position as 0 because as you are at that location. So, now you cannot go to it again.
  3. When you are standing at (0,0) position, you can move 8 different moves: (r-2,c-1), (r-2,c+1), (r-1,c-2), (r-1,c+2), (r+1,c-2), (r+1,c+2), (r+2,c-1), or (r+2,c+1).
  4. You will select a move out of 8 possible moves which will allow you to iterate to maximum location.
    Reason:
    As you can choose only one move from a particular index. So, choosing the move that will give maximum value is optimal.
  5. Suppose, you first go to (r-2,c-1) you will mark this position as 0 in the recursive call.
    But, when you will return from it. Before returning, you will mark it again 1.
    As, thereafter you will go for 7 remaining moves. So, all the positions that we ca reach from (r-2,c-1) can also be reached from any of the other seven moves.
    Thus, if you want make them 1 again. Then you will not get your answer.
1 Like