Flood Rise Minimum Time
A datacenter floor is an n×n grid; cell elevations differ. Water rises uniformly — at time t every cell with elevation ≤ t is submerged and passable. Find the earliest time you can travel from the top-left to the bottom-right, moving only through submerged cells.
Problem
Given an n×n grid where grid[i][j] is the elevation of cell (i,j), return the least time t such that there is a path from (0,0) to (n−1,n−1) using only 4-directional moves through cells with elevation ≤ t.
Input
An n×n integer grid (1 ≤ n ≤ 50); grid contains a permutation of 0..n²−1.
Output
An integer: the minimum time to reach the bottom-right.
Constraints
- 1 ≤ n ≤ 50
- Elevations are a permutation of 0..n²−1
- Moves are up/down/left/right only
Examples
Example 1
Input
grid = [[0,2],[1,3]]
Output
3
At t=3 the path 0→1→3 (or 0→2→3) is fully submerged.
Example 2
Input
grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]
Output
16
The snake path through the lowest possible peak requires waiting until t=16.