Class Solution
-
- All Implemented Interfaces:
public final class Solution1036 - Escape a Large Maze\.
Hard
There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are
(x, y).We start at the <code>source = s<sub>x</sub>, s<sub>y</sub></code> square and want to reach the <code>target = t<sub>x</sub>, t<sub>y</sub></code> square. There is also an array of
blockedsquares, where each <code>blockedi = x<sub>i</sub>, y<sub>i</sub></code> represents a blocked square with coordinates <code>(x<sub>i</sub>, y<sub>i</sub>)</code>.Each move, we can walk one square north, east, south, or west if the square is not in the array of
blockedsquares. We are also not allowed to walk outside of the grid.Return
trueif and only if it is possible to reach thetargetsquare from thesourcesquare through a sequence of valid moves.Example 1:
Input: blocked = \[\[0,1],1,0], source = 0,0, target = 0,2
Output: false
Explanation: The target square is inaccessible starting from the source square because we cannot move.
We cannot move north or east because those squares are blocked.
We cannot move south or west because we cannot go outside of the grid.
Example 2:
Input: blocked = [], source = 0,0, target = 999999,999999
Output: true
Explanation: Because there are no blocked cells, it is possible to reach the target square.
Constraints:
0 <= blocked.length <= 200blocked[i].length == 2<code>0 <= x<sub>i</sub>, y<sub>i</sub>< 10<sup>6</sup></code>
source.length == target.length == 2<code>0 <= s<sub>x</sub>, s<sub>y</sub>, t<sub>x</sub>, t<sub>y</sub>< 10<sup>6</sup></code>
source != targetIt is guaranteed that
sourceandtargetare not blocked.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-