Skip to content
Discussion options

You must be logged in to vote

We need to determine the minimum time required to swim from the top-left corner (0, 0) to the bottom-right corner (n-1, n-1) of an n x n grid, where each cell has a unique elevation. The water level rises over time, and at time t, any cell with an elevation ≤ t is reachable. We can move to adjacent cells (up, down, left, right) only if both the current and target cells have elevations ≤ t.

Approach

  1. Binary Search on Time: We perform a binary search on the possible time values (from 0 to the maximum elevation in the grid) to find the minimum time t such that there exists a path from (0, 0) to (n-1, n-1) where all cells in the path have elevations ≤ t.
  2. Breadth-First Search (BFS) for Path Ch…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Oct 6, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Oct 6, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Oct 6, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants