0
0
DSA Cprogramming~10 mins

Rat in a Maze Problem in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the rat can move to the next cell safely.

DSA C
int isSafe(int maze[4][4], int x, int y) {
    if (x >= 0 && x < 4 && y >= 0 && y < 4 && maze[x][y] == [1]) {
        return 1;
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
A1
B2
C-1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to check for open path.
Not checking boundaries correctly.
2fill in blank
medium

Complete the code to mark the current cell as part of the solution path.

DSA C
solution[x][y] = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Marking with 0 which means no path.
Using negative values which are invalid.
3fill in blank
hard

Fix the error in the recursive call to move right in the maze.

DSA C
if (solveMazeUtil(maze, x + [1], y, solution)) {
    return 1;
}
Drag options to blanks, or click blank then click option'
A2
B-1
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which means no movement.
Using -1 which moves left instead of right.
4fill in blank
hard

Fill both blanks to move down and backtrack correctly.

DSA C
if (solveMazeUtil(maze, x, y + [1], solution)) {
    return 1;
} else {
    solution[x][y] = [2];
    return 0;
}
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 to move down which moves up instead.
Not resetting the solution cell during backtracking.
5fill in blank
hard

Fill all three blanks to check the base case and start the solution.

DSA C
if (x == [1] - 1 && y == [2] - 1 && maze[x][y] == [3]) {
    solution[x][y] = 1;
    return 1;
}
Drag options to blanks, or click blank then click option'
A4
B1
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 which is out of maze bounds.
Checking for 0 instead of 1 in the last cell.