Path With Minimum Effort
MediumGraphs
Decode it first. Clues, constraints, pattern and plan before any code.A hiker walks across a grid of heights, from the top-left cell to the bottom-right cell, moving up, down, left or right. The effort of a route is the largest absolute height difference between two consecutive cells on it. Return the minimum effort of any route.
heights = [[1, 2, 2],
[3, 8, 2],
[5, 3, 5]] → 2 (route 1 → 3 → 5 → 3 → 5 has steps of at most 2)
heights = [[1, 2, 3],
[3, 8, 4],
[5, 3, 5]] → 1 (1 → 2 → 3 → 4 → 5)Constraints
1 <= heights.length, heights[i].length <= 1001 <= heights[i][j] <= 10^6