Phased Infrastructure Activation

A regional utility is restoring service across an n x n industrial site map. Every site (i, j) hosts one facility, and the integer grid[i][j] is that facility's activation threshold, the stage at which its crew finishes the repair work.

Restoration proceeds in discrete stages. At stage t, every facility whose threshold is at most t is online and energized; every facility above the current stage stays offline until the clock reaches it. Two facilities are adjacent when their sites share an edge. An inspection drone may fly directly between two adjacent sites only while both facilities are online, each such flight takes zero extra time once both endpoints are energized, and the drone may begin anywhere inside the depot site (0, 0).

Return the earliest stage t at which the drone can travel from the depot at (0, 0) to the terminal hub at (n - 1, n - 1). The hub counts as reached only once every crossed facility, including the hub itself, is online at stage t or earlier.

Equivalently, model the traversal as follows: the drone may step from (i, j) to an adjacent cell (ni, nj) at any stage t satisfying t >= grid[i][j] and t >= grid[ni][nj]. Any route becomes fully traversable at stage max(grid[i][j]) taken over all cells lying on it, so a route's cost is its largest activation threshold. Find the route from the depot to the hub that minimizes this maximum.

Implement solve(grid) and return that minimum stage t.

Examples
Input: [[0,5,6,7],[4,12,13,8],[3,14,15,9],[2,1,10,11]]
Output: 11
Hints

Phased Infrastructure Activation

A regional utility is restoring service across an `n x n` industrial site map. Every site `(i, j)` hosts one facility, and the integer `grid[i][j]` is that facility's **activation threshold**, the stage at which its crew finishes the repair work.