Graph BFS / DFS
LC #778Hard
Swim in Rising Water
Graph BFS / DFS
GoogleAmazonProblem
Find the minimum time to swim from top-left to bottom-right of a grid, where you can only move to cells with value ≤ current time.
graphdijkstrabinary-searchheap
Constraints
- ›n == grid.length == grid[i].length
- ›1 ≤ n ≤ 50
- ›0 ≤ grid[i][j] < n²
- ›All values unique
Example
Input
grid = [[0,2],[1,3]]Output
3Why
At time 3, path 0→2→3 or 0→1→3 is possible (all cells ≤ 3)