Ratinthemazeprob


what is wrong in this code still ??

@Tiya
It is mentioned in the problem constraints that array can be as large as 1000 X 1000 . You have made an array of 10 X 10 size. This will not be able to hold the input provided and hence not be able to process the case. Increase the size of your array.


still getting wrong ans

@Tiya
Your code prints one less column and one less row on output. Change your printing loops condition to run <= m and n .
That is ,
for(int i=0; i<=m;i++)
and
for(int j=0; j<=n; j++)

Also , if your rightSuccess comes out to be true , do not check for downSuccess as it would give multiple results in output. After you make the call for rightSuccess , check whether its true and return true there only. If it is false , only check for downSuccess in that case.
bool rightSuccess=ratInMaze(maze,soln,i,j+1,m,n);
if(rightSuccess)
{
return true;
}


on getting right=0 then if we get down =1 shouldnt that also return true?


one test case is still failing

Also i have a doubt
on encountering a dead end we are returning false so is that aslo considered as backtracking?
The backtracking step as mentioned in the vdo path print ho jane ke baad sabko 0 karr rha hai…
par on meeting a block we are returning 0 at that very step.Are both considered to be backtracking?

coz evn without the backtracking step it is failing only 1 test case and with it also

@Tiya
Problem in Line No. 54.
First take input of n and then m.
cin >> n >> m;
instead of other way around.

Backtracking step is when we make an assumption that our current path is correct and later it turns out that it was wrong so we correct our assumption.
soln[i][j]=1; //We assume the correct path exists through this cell
.
.
//We check whether our assumption was correct.
.
.
soln[i][j]=0; //If it was wrong , we correct our mistake by marking the current cell as unvisited. This step is the backtracking step as we are going back by tracking our mistake.

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.