************rat and maze

  1. paths are getting printed twice
  2. how can we get the right most path
    https://ide.codingblocks.com/s/336062

@nmaurya760 https://ide.codingblocks.com/s/336064 made some changes in your code look for the comments

all test cases are not passing

hi @nmaurya760 look at the output format carefully, there are spaces between all numbers, print a space after each 1 or 0 and then submit

#include
using namespace std;
bool solve(char arr[][1000], bool sol[][1000], int i, int j, int n, int m){
//base case
if(i==n && j==m){
sol[n][m] = 1;
for(int i=0;i<=n;i++){
for(int 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 rightAns = solve(arr,sol,i,j+1,n,m);

if(rightAns){
	return true;
}
bool bottomAns = solve(arr,sol,i+1,j,n,m);
if(bottomAns){
	return true;
}
sol[i][j] = 0;
return false;

}
int main(){
int n,m;
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 sol[1000][1000];
bool ans = solve(arr,sol,0,0,n-1,m-1);
if(ans == false){
return -1;
}
return 0;
}

hi @nmaurya760 what problem are you facing now? And please share your code using IDE always

All test cases are not passing

hi @nmaurya760
in this part
image
dont return -1 from the main function, print -1 here using cout

1 test case is still not passing

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.