Rat in a Maze all solution is Prining

check the code , it is printing all the possible solution instead of 1 solution

now i’m getting TLE in three test cases

Pramod, you need to maintain a visited array and then before traversing you need to check if that path is already visited earlier or not… Pls refer to this approach as,

sol[i][j]=1;
visited[i][j]=1;
if(j+1<=m && !visited[i][j+1])
{
bool rightSuccess=rat(arr,sol,i,j+1,n,m);
if(rightSuccess==true)
{
return true;
}
}
if(i+1<=n && !visited[i+1][j])
{
bool downSuccess=rat(arr,sol,i+1,j,n,m);
if(downSuccess==true)
{
return true;
}
}
sol[i][j]=0;
return false;
}