Giving segmentation fault

code- https://ide.codingblocks.com/s/321112

You are getting segmentation error because
say u go from i,j to i,j+1 then from i,j+1 u come back to i,j and here you are stuck in an infinite loop
So you have to maintain a visited matrix as well so that u dont revisit the visited node on a particular path

still giving segmentation fault
code- https://ide.codingblocks.com/s/321122

Hey @anubhavb11
looks like u can’t use visited array because its exceeding memory limits and hence giving segmentation error
So instead use ans as visited array if(ans[i][j]==1 then that means u have already included that in your path and simply return .

failing some of the test case
code- https://ide.codingblocks.com/s/321122
but why we are returning when ans[i][j]==1???

We are returning when ans[i][j]=1 because it signify that we have already been on that node.
I am checking you code.

Hey you have to print “NO PATH FOUND” if solution not exist
Please mark it as resolved, if your query is resolved :slight_smile:

see the example we are taking in that all we have to go down and right the if statment of going up or going left will never trigger so why loop is stuck in infinite
and how is the question different from the previous rat in maze

5 4
OXOO
OOOX
XOXO
XOOX
XXOO
In this
we cant go right so we go down we reach (2,1)
now we keep going right we reach at (2,3)
now we cant go right we cant go down now upper or left calls will trigger,

This is how its different from the previous problem that we can move in all directions.

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.