Getting segmentation fault, don’t know the reason.
Segmentation Fault
hello @rachitbansal2500

u have declared an empty size 2d vector.
correct syntax.
vector< vector< char > > arr (n, vector< char > (m) );
Do we always have to do this while declaring a 2D vector?
now the error is in ur rat function
ur code is running in infinite loop.
ecaue now rat can move in all four direction it might happen that we visit same sate again n agin.
to avoid it check whether u have already visited ur current state or not. if it is visited (thats means u r running in a loop) . so return false to avoid loop.
consider this
from (i,j),
move down by 1
then move right by 1
then move up by 1
and then move left by 1.
after these moves u will again reach to same state.
now if u again proceed from that state then u will again take these same steps and this will keep happening again n again . and u will stuck in an infinite loop.
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.