#225MediumGraphs· Dijkstra with a Minimax Cost
Least Effort Hiking Path
Input format
`heights`: a rectangular grid of non-negative integers.
Output format
An integer: the minimum possible effort (0 for a single square).
Examples
Input: heights = [[1, 2, 2], [3, 8, 2], [5, 3, 5]]
Output: 2
The route 1, 3, 5, 3, 5 (down, down, right, right) has steps 2, 2, 2, 2, so its effort is 2. Every route that avoids the 8 needs a step of at least 2, and routes through the 8 are worse.
Input: heights = [[1, 2, 3], [3, 8, 4], [5, 3, 5]]
Output: 1
The route 1, 2, 3, 4, 5 along the top row and down the right column changes by at most 1 per step.
Input: heights = [[7]]
Output: 0
Start and goal are the same square: effort 0.
Constraints
- 1 <= rows, columns <= 100
- 0 <= heights[r][c] <= 10^6
- #dijkstra
- #graph
- #grid
- #heap
- #minimax