3. What will be the output of the following JavaScript code snippet for the Rat in a Maze problem?
const maze = [
[1, 0, 0, 0],
[1, 1, 0, 1],
[0, 1, 0, 0],
[1, 1, 1, 1]
];
function solveMaze(x, y, maze, path) {
if (x === maze.length - 1 && y === maze[0].length - 1) {
path.push([x, y]);
return true;
}
if (x >= 0 && y >= 0 && x < maze.length && y < maze[0].length && maze[x][y] === 1) {
path.push([x, y]);
maze[x][y] = 0;
if (solveMaze(x + 1, y, maze, path)) return true;
if (solveMaze(x, y + 1, maze, path)) return true;
path.pop();
return false;
}
return false;
}
const path = [];
solveMaze(0, 0, maze, path);
console.log(path);