Dodomeki
Sign in

117. Minimum-Effort Crossing

Medium

You are given a height grid alturas. A path starts at the top-left cell and ends at the bottom-right cell. Each move may go to a horizontally or vertically adjacent cell.

The effort of a path is the largest absolute height difference between any two consecutive cells on it. Return the smallest possible effort among all paths connecting these corners.

Example 1
Input: alturas = [[1,2,2],[3,8,2],[5,3,5]]
Output: 2
Explanation: There is a path between the corners whose largest difference between consecutive cells is 2.
Example 2
Input: alturas = [[1,10],[10,1]]
Output: 9
Explanation: Every path must cross a height difference of 9.
Example 3
Input: alturas = [[42]]
Output: 0
Explanation: The starting cell is already the destination, so there are no differences between moves.
Constraints
  • 1 <= alturas.length <= 100
  • 1 <= alturas[i].length <= 100
  • alturas has the same number of columns in every row
  • 1 <= alturas.length * alturas[i].length <= 10^4
  • -10^6 <= alturas[i][j] <= 10^6
GraphsHeapMatrix
Caso 1
alturas =
[[1,2,2],[3,8,2],[5,3,5]]
Expected =
2
Caso 2
alturas =
[[1,10],[10,1]]
Expected =
9
Caso 3
alturas =
[[42]]
Expected =
0

Run checks these 3 cases. Submit runs all 12, including hidden ones.