Swim in Rising Water

Hard · Graphs · about 30 minutes

Asked at Meta, Google, Amazon, Uber.

In an n × n grid, grid[r][c] is the elevation of cell (r, c) (all values distinct, 0..n²-1). At time t, the water everywhere is at depth t, and you can swim between 4-adjacent cells if both elevations are at most t (swimming takes no time). Return the least time at which you can get from the top-left to the bottom-right.

Related guides