Rat in maze output not coming


Hi here is my code. . I am not getting the output.
Any help ?

Hello @rijulsingh1,

There are two mistakes in your code:

  1. line 19 of the following code:
    Wrong condition, leading to no output.

  2. line 32:
    missing conditional check, leading to multiple outputs.

I have corrected it:

Hope, this would help.
Give a like if you are satisfied.

1 Like

hi. ,
but it is showing only 1 output.
I wanted to have all possible paths .
How can this be done?

Hello @rijulsingh1,

I thought that’s exactly what you want: only one path.

A very small change is required and you’ll obtain all the possible paths.
Let’s first understand: why is it printing only 1 path?

As i have mentioned in the comments in the modified code i.e. the point 2 of my previous reply.
If you get a path from moving right then don’t move downwards.
That means you are restricting the movement towards down if you get a path from moving right. Correct?

How are you checking whether you are getting path from moving right or not?
If the recursive call returns true.

When would the recursive call return true?
if you’ll reach the base case where you have to print the path.
As you can see in the code that you are returning true after printing the path, indicating that you have found a path.

Final question: How would you get all the paths?
Just return false instead of true in the base condition.
This way, the condition mentioned at line 32 will never satisfy and you will move down also.
Hence, getting all the paths.

Hope, this would help.

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.