Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the rat can move to the next cell safely.
DSA Python
def is_safe(maze, x, y, n): return x >= 0 and y >= 0 and x < n and y < n and maze[x][y] == [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to check for safe cells.
Not checking boundaries correctly.
✗ Incorrect
The rat can move only to cells with value 1, which means the path is open.
2fill in blank
mediumComplete the code to mark the current cell as part of the solution path.
DSA Python
def solve_maze_util(maze, x, y, n, sol): if x == n - 1 and y == n - 1: sol[x][y] = [1] return True
Attempts:
3 left
💡 Hint
Common Mistakes
Marking the cell with 0 which means no path.
Forgetting to mark the cell at the destination.
✗ Incorrect
Marking the cell with 1 means it is part of the path solution.
3fill in blank
hardFix the error in the recursive call to move right in the maze.
DSA Python
if solve_maze_util(maze, x + [1], y, n, sol): return True
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or -1 which does not move right.
Using y instead of 1 for movement.
✗ Incorrect
To move right, increase x by 1, so x + 1 is correct.
4fill in blank
hardFill both blanks to move down and backtrack correctly.
DSA Python
sol[x][y] = [1] if solve_maze_util(maze, x, y + 1, n, sol): return True sol[x][y] = [2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 or 2 which are invalid markers.
Not resetting the cell during backtracking.
✗ Incorrect
Mark the cell as part of the path with 1, and backtrack by resetting it to 0.
5fill in blank
hardFill all three blanks to complete the dictionary comprehension that stores path steps with their coordinates.
DSA Python
path_steps = [1]: (x, y) for x in range(n) for y in range(n) if sol[x][y] == [2] and maze[x][y] == [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using sol instead of (x, y) for dictionary keys.
Checking for 0 instead of 1 in conditions.
✗ Incorrect
We create a dictionary {(x, y): (x, y)} for path cells where cells marked 1 and maze cells 1 are included.
