Provide me some hint so that i can make a progress
Please give me some hint in approaching this prob
@kodivine0 hey ,
HINT TO SOLVE
- Think recursively.
- Maintain some other matrix, name it “canBeVisitedMatrix[n][n]”
- Initialize this matrix to zero
- Search for the very first 1 (upper left most) in the input matrix and from this make recursive calls to
{ (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) } cells and mark them 1 in our “canBeVisitedMatrix” (These are the vertices which can be visited). - Also make the recursive call for a particular cell only if it is a part of the chessboard.
The cells in our “canBeVisitedMatrix” still marked 0 are the ones that cannot be visited by the knight.
what shall be the return type of the function in which we are making recursive calls?
@kodivine0 hey it all depends on you ,you can take int or make it void and store ans in global variable.
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.
sir, i tried a lot but not able to solve it.