You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at position (i, j).
The rain starts at time t = 0. At time t, the depth of water everywhere is t. You can swim from one square to an adjacent square (up, down, left, right) if and only if the elevation of both squares is at most t. You can swim an infinite distance in zero time.
Return the least time until you can reach the bottom-right corner (n - 1, n - 1) from the top-left corner (0, 0).
0 2 1 3
Input: grid = [[0,2],[1,3]] Output: 3 Explanation: At t=3, all cells have elevation <= 3; we can swim 0->2->3 or 0->1->3. The minimum t is 3.
0 1 2 3 4 24 23 22 21 5 12 13 14 15 6 11 17 18 19 20 10 9 8 7 16
Input: grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,6],[11,17,18,19,20],[10,9,8,7,16]] Output: 16 Explanation: At t=16, you can swim along the spiral path; the highest elevation on the optimal path is 16.
n == grid.length == grid[i].length1 <= n <= 500 <= grid[i][j] < n^2grid is uniquegrid = [[0, 2], [1, 3]]