Path with minimum effort
A delivery robot crosses a field laid out as a grid. heights[r][c] is the height of the ground in the cell at row r, column c. The robot starts in the top-left cell and must reach the bottom-right cell. Each move goes to the next cell up, down, left or right, never off the grid, and a route may visit cells in any order.
The step of a move is the height difference between the two cells, without its sign: going from 3 to 8 and going from 8 to 3 are both steps of 5. The robot's motor only cares about its hardest move, so the effort of a route is its largest step, not the sum of its steps. A route with no moves has effort 0. Return the smallest effort of any route from the top-left cell to the bottom-right cell.
heights = [[1, 6, 2], [3, 8, 4], [5, 7, 6]]Output2Down the left side and along the bottom: 1, 3, 5, 7, 6. Its steps are 2, 2, 2 and 1, so the effort is 2. No route does better, because both first steps (1 to 3, and 1 to 6) are at least 2.
heights = [[1, 4, 2]]Output3One row, so one route: steps of 3 and 2. The effort is the larger one, 3.
heights = [[7]]Output0The start is the goal, so there are no steps and the effort is 0.
1 ≤ rows, cols ≤ 100
1 ≤ heights[r][c] ≤ 106
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.