Swim in Rising Water
You are given an n x n grid where grid[i][j] is the elevation at cell (i, j). Rain falls and at time t the water level is t everywhere. You can swim from a cell to a 4-directionally adjacent cell only if both cells' elevations are at most the current time t; swimming is instantaneous. Starting at (0, 0), return the least time t at which you can reach (n-1, n-1).
Open official problem prompt ↗Find the earliest moment the rising water lets you walk from the top-left to the bottom-right, which equals the lowest possible peak elevation on any connecting path.
Like flooding a valley slowly: you can only cross a ridge once the water rises above it, so you wait for exactly the lowest ridge that still connects start to finish.
- Input
- grid = [[0,2],[1,3]]
- Output
- 3
- Why
- You must reach the bottom-right cell whose elevation is 3, so no path can complete before time 3.
n == grid.length == grid[i].length1 <= n <= 500 <= grid[i][j] < n*nEach value in grid is unique