Binary Maze Reachability
Problem statement
You are given a nonempty rectangular binary matrix maze. A cell containing 1 is passable, and a cell containing 0 is blocked.
The two arrays start and destination contain zero-based coordinates in the form [row, column]. From a passable cell, each move goes exactly one cell up, down, left or right to another passable cell inside the matrix.
Return true if a route from start to destination exists; otherwise return false. If either endpoint is blocked, return false. A passable cell can reach itself using zero moves.
Function
canReachMaze(maze: int[][], start: int[], destination: int[]) → booleanExamples
Example 1
maze = [[1,1,0],[0,1,1],[1,0,1]]start = [0,0]destination = [2,2]return = trueOne route is (0,0) -> (0,1) -> (1,1) -> (1,2) -> (2,2). Every visited cell contains 1, and each move joins orthogonally adjacent cells.
Example 2
maze = [[1,0,1],[0,1,0],[1,0,1]]start = [0,0]destination = [2,2]return = falseThe start has no passable orthogonal neighbor. The diagonal passable cells do not connect it to the destination.
Example 3
maze = [[1,0,1],[1,1,1]]start = [0,0]destination = [0,2]return = trueA route goes down to (1,0), right through (1,1) and (1,2), then up to (0,2). Moving only right and down would miss this valid route.
Constraints
1 <= maze.length <= 40.1 <= maze[row].length <= 40; every row has the same length.- Every cell is
0or1. start.length == destination.length == 2.- Both coordinates name cells inside the matrix:
0 <= row < maze.lengthand0 <= column < maze[0].length.