algorythms
Graph BFS / DFS
LC #778Hard

Swim in Rising Water

Graph BFS / DFS
GoogleAmazon

Problem

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

Inputgrid = [[0,2],[1,3]]
Output3
Why

At time 3, path 0→2→3 or 0→1→3 is possible (all cells ≤ 3)

Hints — reveal one at a time