Swim In Rising Water
At time t you may enter grid cells with elevation <= t. Return the smallest t allowing an orthogonal path from top-left to bottom-right.
Example 1
0,00
0,12
1,01
1,13
grid = [[0,2],[1,3]]3Explanation
Destination elevation 3 forces time at least 3, and a path exists by that time.
Example 2
0,00
grid = [[0]]0Explanation
Start and finish are the same elevation-zero cell.
Example 3
0,00
0,11
0,22
1,05
1,14
1,23
2,06
2,17
2,28
grid = [[0,1,2],[5,4,3],[6,7,8]]8Explanation
Destination elevation 8 is a lower bound; time 8 makes the whole grid traversable.
Constraints
- Grid is n by n with 1 <= n <= 50
- Elevations are a permutation of 0..n*n-1
Function contract
swimInWaterArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[[0,2],[1,3]]