The Question
CodingSwim in Rising Water
You are given an $n \times n$ integer matrix
grid where each value grid[i][j] represents the elevation at that point $(i, j)$. It starts raining, and water gradually rises over time. At time $t$, the water level is $t$, meaning any cell with elevation less than or equal to $t$ is submerged and can be swam through.
You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most $t$. You can swim infinite distances in zero time. You must stay within the boundaries of the grid.
Return the minimum time $t$ required to reach the bottom-right square $(n - 1, n - 1)$ starting from the top-left square $(0, 0)$.
### Constraints
- $n == \text{grid.length} == \text{grid[i].length}$
- $1 \le n \le 50$
- $0 \le \text{grid}[i][j] < n^2$
- Each value in grid is unique.Java
Dijkstra's Algorithm
Priority Queue
Disjoint Set Union