Problem
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.
Example 1
heights = [[1, 2, 2],
Example 2
[3, 8, 2],
Example 3
- Input
- [5, 3, 5]]
- Output
- 2
- Why
- route 1 → 3 → 5 → 3 → 5 has steps of at most 2
Example 4
heights = [[1, 2, 3],
Example 5
[3, 8, 4],
Example 6
- Input
- [5, 3, 5]]
- Output
- 1
- Why
- 1 → 2 → 3 → 4 → 5
Constraints
1 <= heights.length, heights[i].length <= 1001 <= heights[i][j] <= 10^6