In my current code , the output shows for some matrix and for some others it does not show.
Eg- OXO
OOX
XOO
OXO
The above matrix is one of the examples where the code works whereas for the sample test case given it is getting segmentation fault even though when I dry run it , it should work properly.
Please help me in showing where my code is going wrong.
Thank You.
Code getting Segmentation Fault
hello @paulayush2002 i dont uderstand your logic of the code ,in this question we have to print the right most path right ?
In the question it is given that there will be only one unique path for the mouse to reach the end,and we have to print that path.
For the code,the string s denotes that when we are in some cell (i,j) we need to move in such a way so that we do not move backwards and that backwards can be up,down,left or right as the mouse could have come to the current position from previous position by moving from any of the direction. Let us say the mouse comes to the current position by moving right from the previous position then the mouse should not move to left before checking all the other three options and only if other three options are false will the mouse backtrack.
Hope , I was able to understand you my code.
yes wait .
try this :
if you have any doubt in this you can ask here.
Happy Learning !!
I do understand the code ,but it is passing only one test case.
I think it may be because your code is only going either down or right whereas the mouse has the option to move in up and left direction also and that means for some test cases,it may have backtracked in the up or left direction as well.
no left and up mean to backtrack the way .
could you please share the question link on hackerblocks?
It is the Rat and Cheese Problem in the BackTracking Section of the Challenges.
yes i have written the code for the same question .
first you need to clear your misunderstanding for up and down but the concept is actually you need to traverse through the path and if at ny point you find that there is no path forward available then you need to backtrace that path again by moving up and left .
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.