Rat in a maze problem

this is my code my 1 test case is wrong and 1 is showing TLE and rest test cases are passed succesfullt please tell me mistake

// #include
using namespace std;
bool rat(char arr[][1000],int sol[][1000],int i,int j,int n,int m)
{
if(i==n-1&&j==m-1)
{
sol[i][j]=1;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cout<<sol[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
return true;
}
if(i>n||j>m)
return false;
if(arr[i][j]==‘X’)
{
return false;
}
sol[i][j]=1;

bool right=rat(arr,sol,i,j+1,n,m);
bool down=rat(arr,sol,i+1,j,n,m);
sol[i][j]=0;
if(right||down)
return true;

return false;

}
int main() {
int n,m;
int sol[1000][1000]={0};
cin>>n>>m;
char arr[1000][1000];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cin>>arr[i][j];
}
bool ans=rat(arr,sol,0,0,n,m);
if(ans==false)
cout<<"-1";

return 0;

}

Hi @lovish2552 you have to check the down path only if right path does not exist as you have to print a single path only

can you tell me what changes i can do in my code

@lovish2552 please share your code by saving it in cb ide i’ll make changes in that itself


this is the link please reply fast

@lovish2552 https://ide.codingblocks.com/s/293489

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.