Why run-time error?

#include<bits/stdc++.h>
using namespace std;;

bool hasPath(vector grid, vector<vector> &path,int i, int j){
if(grid[i][j]==‘X’){
return false;
}
if(i==grid.size()-1 && j==grid[0].size()-1){
path[i][j]=true;
return true;
}
if(j<grid[0].size()-1 && hasPath(grid,path,i,j+1)){
path[i][j]=true;
return true;
}
else if(i<grid.size()-1 && hasPath(grid,path,i+1,j)){
path[i][j]=true;
return true;
}
else{
return false;
}
}

int main() {
int n,m;
cin>>n>>m;
vector grid;
for(int i=0;i<n;i++){
string temp;
cin>>temp;
grid.push_back(temp);
}
vector<vector> path(n,vector(m,false));
bool check=hasPath(grid,path,0,0);
if(check){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(path[i][j]){
cout<<"1 ";
}
else{
cout<<“0 “;
}
}
cout<<endl;
}
}
else{
cout<<”-1”<<endl;
}
return 0;
}

hi @nakshjain buddy refer

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.