FastPrepSwim in Rising Water
Problems/Swim in Rising Water

Swim in Rising Water

Google logoGoogle● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand new-grad report from Google asks for a path from (0,0) to (m-1,n-1) that minimizes the largest distinct height met along the way. It reports a Dijkstra solution, and asks whether DFS is possible and what its complexity would be. A commenter names the task as a well-known problem.

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[][]) → int

Examples

Example 1

grid = [[0,2],[1,3]]return = 3
grid
01002113

Every 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 = 16
grid
01234001234124232221521213141516311171819204109876

The winding low-height route reaches the target without using a cell above 16.

Example 3

grid = [[7]]return = 7
grid
007

The 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 200000 cells.
  • 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

Interview reports that mention this question

  • Google New Grad R1 Swim in Rising Water and BQ: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int swimInWater(int[][] grid) {
        // Write your code here.
    }
}
Checking account…