Rat chases its cheese

What’s wrong in the code??

Your Mistakes

  1. your function is not called
if(grid[m][n]=='O')

        solve(0,0,grid,soln,m-1,n-1);

correct Condition to check is
if(grid[m-1][n-1]=='O')
	    solve(0,0,grid,soln,m-1,n-1);
  1. if(i+1<n && !vis[i+1][j] && a[i+1][j]=='O'){
    this is incorrect
    correct condition will be
    if(i+1<=m && !vis[i+1][j] && a[i+1][j]=='O'){

Modified Code

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.