Complete the code to check if the rat can move to the cell (x, y) inside the maze boundaries.
bool IsSafe(int x, int y, int[,] maze, int n) {
return (x >= 0 && y >= 0 && x < [1] && y < n && maze[x, y] == 1);
}The maze is a square matrix of size n x n. To check if x is within bounds, we use maze.GetLength(0) which returns the number of rows.
Complete the code to move the rat downwards in the maze recursion.
if (SolveMazeUtil(maze, x + [1], y, solution, n)) { return true; }
To move down, we increase the row index by 1, so x + 1.
Fix the error in marking the current cell as part of the solution path.
solution[x, y] = [1];Marking the cell as 1 means it is part of the path.
Fill both blanks to backtrack correctly by unmarking the cell and returning false.
solution[x, y] = [1]; return [2];
Backtracking means unmarking the cell by setting it to 0 and returning false to try other paths.
Fill all three blanks to complete the recursive calls for moving right and backtracking.
if (SolveMazeUtil(maze, x, y + [1], solution, n)) { return [2]; } solution[x, y] = [3];
Moving right means y + 1, returning true if path found, else unmark cell by setting to 0.
