2 test case giving WA

RAT IN A MAZE
You are given an N*M grid. Each cell (i,j) in the grid is either blocked, or empty. The rat can move from position (i,j), down or right on the grid.
Initially rat is on the position (1,1). It wants to reach position (N,M). Find the rightmost path through which, rat can reach this position. A path is rightmost, if the rat is at position (i,j), it will always move to (i,j+1), if there exists a path from (i,j+1) to (N,M).

Your code is showing TLE in one test case, so to avoid that maintain a visited array as
int visited[1001][1001]; and then when you are initializing your solution matrix as 1, use
solution[i][j]=1;
visited[i][j]=1;
and then before you go downwards or right, pls check,
if(j+1<=M && !visited[i][j+1])
{
bool rightSuccess=ratmaze(maze,i,j+1,N,M);
if(rightSuccess==true)
{
return true;
}

Use this logic and then try to submit .