Cant figure out why i am getting run error for one test case.
All others are correct.
I am getting run error in 1 test case for Rat Chases its cheese
Maintain a visited array to check the path that is already visited… You can follow the approach as :
visited[i][j]=true;
bool rightSuccess,downSuccess,topSuccess,leftSuccess;
if(visited[i+1][j]==false && ans[i+1][j]==0)
{
downSuccess=sol(a,ans,i+1,j,n,m);
}
if(visited[i][j+1]==false && ans[i][j+1]==0)
{
rightSuccess=sol(a,ans,i,j+1,n,m);
}
if(ans[i-1][j]==0)
{
topSuccess=sol(a,ans,i-1,j,n,m);
}
if(ans[i][j-1]==0)
{
leftSuccess=sol(a,ans,i,j-1,n,m);
}
1 Like
Thanks! That worked.