How to Print only 1 path in Rat In a Maze Problem?

//base case
if(i==n and j==m)
{   
    output[i][j]=1;
	//print path
	for(int x=0;x<=n;x++)
	{
		for(int y=0;y<=m;y++)
		{
			cout<<output[x][y]<<" ";
		}
		cout<<endl;
	}
return true;
}

if(i>n || j>m){
    return false;
}
if(input[i][j]=='X'){
    return false;
}
output[i][j]=1;

bool downSuccess = ratProblem(input,output,i+1,j,n,m);
bool rightSuccess =  ratProblem(input,output,i,j+1,n,m);

output[i][j]=0;
if(downSuccess || rightSuccess){
    return true;
}
return false;

}

The above code prints multiple solutions but I want only one . I am unable to make the needed changes.

hello @ritkumar

add an if statement after this .
if (dowsuccess is true) return true

1 Like

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.