Learn
Exam

Maze Escape 1

Difficulty
BEGINNER

Problem

Write a solution function that takes as its parameter a maze represented by an n×nn \times n grid maze of width and height n, consisting only of passages (0) or walls (1). The function should return whether it is possible to travel from (1, 1) to (n, n).

Assume that it is not possible to move outside the bounds of the given maze maze.

Constraints

  • The maze is given as an n×nn \times n square grid where the width and height are natural numbers between 3 and 500 inclusive.
  • All elements of maze are either 0 (passage) or 1 (wall).
    • 0 (passage) represents a traversable path in the maze.
    • 1 (wall) represents an impassable obstacle in the maze.
    • The element (1, 1) in the first row and first column and the element (n, n) in the ( n )-th row and ( n )-th column will always be 0.

Test Case

Test Case Number maze return
1 [[0,1,0,1],[0,1,1,0],[1,0,0,0],[0,0,1,0]] false
2 [[0,1,1],[0,0,0],[0,1,0]] true
3 [[0,0,1,0,1],[0,0,0,1,1],[0,0,1,1,1],[0,1,0,0,0],[1,1,0,1,0]] false

Explanation for Test Case 1

  • In the given input, it is not possible to travel from (1, 1) to (4, 4).

Explanation for Test Case 2

  • In the given input, there is a path from (1, 1) to (3, 3): (1,1)→(2,1)→(2,2)→(2,3)→(3,3) (1,1) \rightarrow (2,1) \rightarrow (2,2) \rightarrow (2,3) \rightarrow (3,3)

Explanation for Test Case 3

  • In the given input, it is not possible to travel from (1, 1) to (5, 5).

Additional Notes

  • If python development environment shows errors such as runtime errors for test cases 11, 14, 15, refer to the following:
    • Python limits the maximum recursion depth to 1,000.
    • If the recursion depth is exceeded, a runtime error RecursionError will occur.
    • To adjust the maximum recursion depth in Python, you should write the code as shown below:
import sys
sys.setrecursionlimit(10**6)
 
def solution(n, edges):
  return 0
``