You are given an n x n grid of non-negative integers. Each value represents the earliest time at which that cell becomes traversable.
You start at the top-left cell (0, 0) at time 0 and want to reach the bottom-right cell (n - 1, n - 1). At any time T, you may stand on or move into a cell only if its value is less than or equal to T. You may move one step at a time in the four cardinal directions: up, down, left, and right.
Return the minimum time T such that there exists a valid path from the top-left corner to the bottom-right corner.
Example:
-
Input:
grid = [
[0, 2],
[1, 3]
]
-
Output:
3
Because you cannot enter the bottom-right cell until time 3, the earliest feasible path is available at T = 3.
Discuss possible approaches such as priority queue traversal, binary search with reachability checking, or disjoint set union.