Problem
Write a solution function that takes as its parameter a maze represented by an 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
mazeis given as an square grid where the width and height are natural numbers between 3 and 500 inclusive. - All elements of
mazeare 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):
Explanation for Test Case 3

- In the given input, it is not possible to travel from
(1, 1)to(5, 5).
Additional Notes
- If
pythondevelopment 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
RecursionErrorwill 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
``