LeetCode 778 Swim in Rising Water - Problem Statement

The problem

Given an n × n grid where grid[i][j] represents elevation, find the minimum time to swim from top-left to bottom-right.

At time t, you can swim through any cell with elevation t\le t. You start at time t = grid[0][0] (must wait until water rises to your starting elevation).

With grid = [[0,2],[1,3]]:

  • At t=0: Can only be at (0,0).
  • At t=1: Can reach (1,0).
  • At t=2: Can reach (0,1).
  • At t=3: Can reach (1,1).
  • Answer: 3.

Return the minimum time to reach (n-1, n-1).

Constraints: 1n501 \le n \le 50. Each cell value is unique and in [0,n21][0, n^2-1].