Matrix Water Injection 08/10
Given a two-dimensional matrix, the value of each grid represents the height of the terrain. The flow of water will only flow up, down, right and left, and it must flow from the high ground to the low ground. As the matrix is surrounded by water, it is now filled with water from (R,C) and asked if water can flow out of the matrix.
The input matrix size is n x n,
n <= 200.Ensure that each height is a positive integer.
Have you met this question in a real interview? Yes
Example
Given
mat =
[
[10,18,13],
[9,8,7],
[1,2,3]
]R = 1, C = 1, return "YES"。
Explanation:
(1,1) →(1,2)→Outflow.Given
mat =
[
[10,18,13],
[9,7,8],
[1,11,3]
]R = 1, C = 1, return "NO"。
DFS
BFS
Last updated