Wading Across a Flooding Field
Implement floodLevel
A field is described by a grid of elevations. As time passes, every cell whose elevation is at most t floods, and you can walk between flooded cells that share a side. Find the earliest time at which you can walk from the top-left cell to the bottom-right cell.
The answer is the smallest possible height of the highest cell on a route. Flooding the cells from lowest to highest and merging neighbouring flooded cells with union-find finds the exact moment the two corners become connected.
Example 1:
Input: elevation = [[4,9,2],[7,3,8],[6,5,1]]
Output: 7
Example 2:
Input: elevation = [[6]]
Output: 6
Example 3:
Input: elevation = [[1,9],[9,2]]
Output: 9
+ 13 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ rows, cols ≤ 8; 0 ≤ elevation[r][c] ≤ 99 (values may repeat) - ●
At time t every cell with elevation ≤ t is flooded to knee height; you may stand on and walk between flooded cells that share a side (up, down, left, right) - ●
You start on the top-left cell and want to reach the bottom-right cell; both must also be flooded - ●
Return the earliest time t at which such a walk exists (equivalently, the smallest possible value of the highest cell on any route)
elevation =
[[4,9,2], [7,3,8], [6,5,1]]