Swim in Rising Water
HardGraphs
Decode it first. Clues, constraints, pattern and plan before any code.An n x n grid gives the elevation of each square, and every value from 0 to n² - 1 appears exactly once. Rain starts, and at time t the water everywhere is at height t. You can swim from a square to a side neighbour up, down, left or right whenever both squares have elevation at most t, and swimming takes no time. Return the least time at which you can get from the top-left square to the bottom-right square.
[[0, 2],
[1, 3]] → 3 (you cannot leave the last square's height 3 out of any route)
[[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]] → 16Constraints
1 <= n <= 500 <= grid[i][j] < n²- Every value in the grid is unique