Swim in Rising Water
Updated
Problem statement
A rectangular grid contains distinct integer heights. Start at the top-left cell and move up, down, left, or right until reaching the bottom-right cell.
The cost of a path is the maximum height on that path. Return the minimum possible path cost.
Function
swimInWater(grid: int[][]) → intExamples
Example 1
grid = [[0,2],[1,3]]return = 3Every route ends at height 3, so the minimum possible maximum is 3.
Example 2
grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]return = 16The winding low-height route reaches the target without using a cell above 16.
Example 3
grid = [[7]]return = 7The only path contains the start cell itself.
Constraints
1 <= grid.length, grid[i].length <= 500.- Every row has the same length.
- The grid has at most
200000cells. - All heights are distinct integers in
[0, 1000000000].
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Shortest Path with Directional Move CostsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Minimum-Cost Path Through a Weighted GridVisa · OAVisa interview questions
- Cookie Monster Minimum Arrival TimeIntuit · OAIntuit interview questions
- Swim in Rising WaterUiPath · PHONE SCREEN
- Shortest Path in a Grid with Obstacles EliminationMercor · PHONE SCREENMercor interview questions
- Dynamic Broadcast TimesNetflix · PHONE SCREENNetflix interview questions
- Shortest Path in a Grid with Obstacles EliminationBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Shortest Grid Path with Weighted ObstaclesApple · PHONE SCREENApple interview questions