Funky chess board

didnt understood the problem clearly can anyone explain with better test case test case is also not that much of explanatry what is the meaning of minimum in this case of the problem

see the chess board is not placable positions( where nights can be kept) 1 denotes yes knight can be placed , 0 denotes the knight is not placable, invalid position

so the question asks u the maximum no of positions the knight can travell starting from 0,0
u have a dfs call for all 8 possible moves from each cell

Minimize the no of unvisited cells means that knight is able to visit the maximum no of valid positions in the board.
eg:
3
1 1 1
1 1 1
1 1 1
all board positions are 1
so maximum visible cells are 9
now i start the knight from 0,0 have all 8 dfs call at each position
getting to see that knight can move on 8 valid cells at max
hence 9-8 == 1 is the answer
1 cell is left unvisited

If the test case is 4
1 1 0 0
0 1 1 1
1 1 0 0
1 0 0 1
Can you explain with this test case?

image

just 2 positions are not reachable
1,1 and 3,0
i have showed the step no. when the knight reaches that cell
this is the most optimal way in which we can minimize the unreachable position

1 Like

Oh great thanks mam… Neat explanation…

1 Like


mam how can i modify this code to print maximu traversed path it is working fine for giving the minimum number but cant able to figure out how to print that path…

yr yeh to mujhe bhi nhi pata i tried but hua nhi

So the example you provided in upper discussion is written by you?? By checking all conditions??

ya ya
i made that diagram

1 Like