Rat in a maze problem

Where my approach is getting wrong

Hey @coderajay03 what issues are you facing in this code?

am getting absurd result you can use test case
5 4
OXOO
OOOX
OOXO
XOOO
XXOO

i have edited your code here, there were mistakes in calling recursion.

still not able to pass all test cases

That might be because of the output function, which test cases are you failing?

Moreover in line 48 add endl statement too

If it still doesn’t pass test cases after adding endl statement then do let me know.

only passing test case 3

Try submitting this code

sir, I don’t need an answer I want understanding and that could be attained only by working on my thought process so please let me know where I am doing wrong and what what the consequence that wrong code will lead to so I can correct myself .
Thankyou

Yes I can surely tell you. One reason is in the for statement of your if statement.
In your next if statement you are checking for next right and next down step what if your starting is blocked and you are not checking for that. what You were losing is not checking current I,j index but I+1,j and I,j+1 index
And last your return statement wasn’t placed at correct position causing in false output.

1 Like

okay ok I got it !!
Thankyou so much

Then @coderajay03 please mark your doubt as resolved :slight_smile:

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.