it shows segmentation fault
#include
using namespace std;
bool RatinMaze(char maze[][1001],int soln[][1001],int m,int n,int i,int j){
// base case
if(i==m && j==n){
soln[m][n]=1;
// prints
for(int i=0;i<=m;i++){
for(int j=0;j<=n;j++){
cout<<soln[i][j]<<" ";
}cout<<endl;
}
return true;
}
// recursive case
if(i<0 || j<0){
return false;
}
if(i>m or j>n ){
return false;
}
if(maze[i][j]==‘X’){
return false;
}
soln[i][j]=1;
bool right=RatinMaze(maze,soln,m,n,i,j+1);
if(right)
return true;
bool down=RatinMaze(maze,soln,m,n,i+1,j);
if(down){
return true;
}
bool up=RatinMaze(maze,soln,m,n,i-1,j);
if(up){
return true;
}
bool left=RatinMaze(maze,soln,m,n,i,j-1);
if(left){
return true;
}
soln[i][j]=0;
return false;
}
int main() {
int m,n;cin>>m>>n;
char maze[1001][1001];int soln[1001][1001];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>maze[i][j];
}
}
bool ans=RatinMaze(maze,soln,m-1,n-1,0,0);
if(!ans){
cout<<"-1";
}
}