Rat chase its cheese

what’s wrong in my code?
out of 5, 3 test cases got success.

#include
#include
using namespace std;

int count=0;
bool ratInMaze(string maze[1000], int soln[1000][1000], int i, int j, int n, int m){
if(i==n && j==m){
soln[n][m] = 1;
count++;
if(count == 1){
for(int i=0; i<=n; i++){
for(int j=0; j<=m; j++){
cout<<soln[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
return true;
}
if(i>n || j>m){
return false;
}
if(i<0 || j<0){
return false;
}
if(soln[i][j] == 1){
return false;
}
if(maze[i][j] == ‘X’){
return false;
}
soln[i][j] = 1;

bool rightSuccess = ratInMaze(maze, soln, i, j+1, n, m);
bool downSuccess = ratInMaze(maze, soln, i+1, j, n, m);
bool leftSuccess = ratInMaze(maze, soln, i, j-1, n, m);
bool upSuccess = ratInMaze(maze, soln, i-1, j, n, m);

soln[i][j] = 0;

if(rightSuccess || downSuccess || leftSuccess || upSuccess){
	return true;
}
return false;

}

int main() {
int n, m;
cin>>n;
cin>>m;
string maze[1000];
for(int i=0; i<n; i++){
cin>>maze[i];
}
int soln[1000][1000] = {0};
bool ans = ratInMaze(maze, soln, 0, 0, n-1, m-1);
if(ans == false){
cout<<"-1";
}
return 0;
}

@sharmarachit19962000 share the code using cb ide

@sharmarachit19962000 check for this
4 4
OOOO
OOOO
OOOO
OOOX

So, in this case we’ll put a checkin base case.

if(i==n && j==m){
if(maze[i][j] == ‘X’){
return false;
}

@sharmarachit19962000


print no path found in caps not -1

Okay, Thanks
Sorry, for such silly mistake.

@sharmarachit19962000 you are welcome :smiley: