Please discuss the algorithm for this question?

I am not able to think the algorithm using backtracking so please make me understand it

hello @namangarg31
this problem is very similar to rat in maze .
the only difference is here mouse is allowed to move in all directions .
so what exaclty u need to do is instead of calling only in two directions, call in all four directions and if at any point u hit base case just print the path and return true.

here u also need to keep track of visited state to avoid loop (visiting same node again again).

if u r not getting then i will suggest to solve rat in maze first .
and then it will be very easy for u

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.