Path With Minimum Effort
Given a rows x cols grid of heights, you start at the top-left cell and want to reach the bottom-right cell moving up/down/left/right. A route's effort is the maximum absolute height difference between two consecutive cells along it. Return the minimum effort over all routes.
Open official problem prompt ↗Find a top-left to bottom-right route whose single hardest climb (largest height jump) is as small as possible.
A hiker crossing terrain cares only about the steepest single step they must take, not the total elevation change; they seek the route with the gentlest worst step.
- Input
- heights = [[1,2,2],[3,8,2],[5,3,5]]
- Output
- 2
- Why
- The route along the top row then the right column keeps every step's height difference at most 2, and no route can guarantee a smaller maximum step.
rows == heights.lengthcols == heights[0].length1 <= rows, cols <= 1001 <= heights[i][j] <= 10^6