Run-Error in rat chase its cheese problem

hello, I am getting run-error on the 4th test case of the the problem Rat chases its cheese and I don’t understand why

problem link - https://hack.codingblocks.com/contests/c/259/570
code link - https://ide.codingblocks.com/s/43290

please help me out.
thanks.

Can u tell me the purpose of using pos.
and I got one error
if(maze[i-1][j]!=‘X’ && i-1>=0 && pos!=4)

In —>if(A && B ) first condition A is checked and if is true than second statement is checked.
now consider that maze[i-1][j] not exist as for i=0 so, u have to first write i-1>=0 and then maze[i-1][j].

Correct Format:
if(i-1>=0 &&maze[i-1][j]!=‘X’ && pos!=4)
Wrong format
if(maze[i-1][j]!=‘X’ && i-1>=0 && pos!=4)

Hit like if u get it

1 Like

I used the parameter pos to ignore checks like if the call to the current position in from a node above it then it is not required to check for path from the above node.

But it will not stop infinte loop.
As in test case
OOX
OOX
XXX

U will move in loop of first square.

Refer this discussion for improvement in your code.

your code will get into infinite loop check this
https://ide.codingblocks.com/s/44348