Problem
You get an n x n grid grid. The value grid[i][j] is the height of the cell at row i and column j. All the heights are different.
Rain starts at time 0. At time t, the water level is t everywhere. At time t, you can swim from a cell to a neighbor cell when both cells have a height of at most t.
A neighbor cell is directly above, below, left or right. You can swim any distance in no time. You start at the top-left cell [0, 0].
Return the earliest time at which you can reach the bottom-right cell [n - 1, n - 1].
Example 1
- Input:
- grid = [[0,3],[2,1]]
- Output:
- 2
- Explanation:
- At time 2, you can swim from height 0 to height 2 and then to height 1. The path through height 3 needs time 3.
Example 2
- Input:
- grid = [[0,6,1],[2,8,3],[7,5,4]]
- Output:
- 6
- Explanation:
- The best path goes from height 0 through the heights 6, 1, 3 and 4. Every other path goes through height 7 or 8.
Constraints
- n == grid.length
- n == grid[i].length
- 1 <= n <= 50
- 0 <= grid[i][j] < n^2
- Each value grid[i][j] is unique
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Calculate Trapping Rain Water
Coding
- Container With Most Water
Coding · Array · Greedy · Two Pointers
- Earliest Finish Time for Land and Water Rides I
Coding
- Earliest Finish Time for Land and Water Rides II
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Meta
Leetcode 778. Swim in Rising Water
Reported Nov 25, 2025 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View source