Wrong output check my code
mistakes
- in base case run loop till m and n not less than m and n
correct one
if (i == m && j == n)
{ solu[m][n] = 1;
for (i = 0; i <=m; i++)
{
for (j = 0; j <=n; j++)
{
cout << solu[i][j] << " ";
}
cout << endl;
}
return true;
}
bool rightSuc = ratInMaze(maze, solu, i, j + 1, m, n);
if (rightSuc)return true;
bool downSuc = ratInMaze(maze, solu, i + 1, j, m, n);
solu[i][j] = 0;
return downSuc;
this is correct way to call recustion
first go to right if right success then return true
if not only then call down and after that return whatever downcall return
- also make size of arrays according to constraints 1000X1000
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like
: and don’t forgot to mark doubt as resolved 