You are given an `n x n` integer matrix `grid` where each value `grid[i][j]` represents the elevation at that point `(i, j)`. The rain starts to fall. At time `t`, the depth of the water everywhere is `t`. 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 start at the top left square `(0, 0)`. What is the least time until you can reach the bottom right square `(n - 1, n - 1)`?
Dijkstra's Algorithm (Min-Max Path)
This is a shortest path problem where the 'cost' of a path is defined as the maximum elevation encountered along it. We want to find a path from `(0, 0)` to `(n-1, n-1)` that minimizes this maximum elevation. Using Dijkstra with a min-priority queue allows us to always explore the lowest possible 'time' to reach any cell.