TLE in one of the test cases

https://ide.codingblocks.com/s/207031 Please Help it is showing TLE in one of the test case.

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…
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;
}
}

Try to implement this along with the approach you have used…to prevent TLE…