Swim in rising water
Your task
You are given an n x n grid where grid[r][c] is the elevation of cell (r,c). At time t the water level is t, and you can be at cell (r,c) only if grid[r][c] <= t. From the top-left cell you may move to a 4-directionally adjacent cell instantly if both cells are below the current water level. Return the least time t at which you can reach the bottom-right cell. (Equivalently, minimize the maximum elevation along a path from corner to corner.)
Examples
swim_in_water(grid: list[list[int]]) -> intExample 1
Input
swim_in_water([[0, 2], [1, 3]])Output
3