Why only 2 testcases are not passing?
You can maintain a visited array as, int visited[1000][1000]… and then before traversing, check if you have already visited that path before or not… This should be done to print unique path…
sol[i][j]=1;
visited[i][j]=1;
if(j+1<=M && !visited[i][j+1])
{
bool rightSuccess=ratInmaze(maze,sol,i,j+1,m,n);
if(rightSuccess==true)
{
return true;
}
}
if(i+1<=N && !visited[i+1][j])
{
bool downSuccess=ratInmaze(maze,sol,i+1,j,m,n);
if(downSuccess==true)
{
return true;
}
}
I’ve tried,but showing wrong output
I have edited your code… Try to submit it now…