code showing stack overflow error.
code link : https://ide.codingblocks.com/s/99350
Rat chases its cheese error
Your code is correct, but one thing is missing. Since the rat can travel in all four directions, it is possible that the same paths are traversed again and again. This could lead to an infinite loop and hence you are getting a stack overflow error. You will have to keep a boolean 2-D array ‘visited’ to mark the positions where the rat has already gone and keep a check that that position is not visited again. And just like you are doing for your solution array, you will have to change back the value of visited if path is not found after all the calls.
can u plzz update my code?
No, that would mean me writing the code for you and you won’t learn that way. You should update it yourself.
i have tried everything to build visited array and tried to mark the positions where rat has already visited but unable to do it plzz help me up with my code.
What problem are you facing with that? Share your updated code and I’ll help you find your mistake
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.