Rat chases its cheese


not getting the correct output for all test cases
please check my code

Sonu, you are required to solve this question using recursion and backtracking instead of using linked list… So pls change the approach you are using in your code…

1 Like

OO sorry
i have posted wrong code


this is my code for rat.
its ending to an undefined output.
please mark the mistake .

I have edited your code… Try to submit now…

Also, you need to maintain a visited path array here, when you are initialising the solution matrix to 1, and its mentioned in the problem that you have to print the extreme rightmost path only, so for that , you need to only include two conditions as,
if(visited[i][j+1]==false && solution[i+1][j]==0)
{
downSuccess=ratmaze(maze,solution,i+1,j,N,M);
}
if(visited[i][j+1]==false && solution[i][j+1]==0)
{
rightSuccess=ratmaze(maze,solution,i,j+1,N,M);
}

Rest code will remain same…Try to implement this otherwise all test cases wont be passed…