Dataford
Interview Guides
Upgrade
All questions/Coding/Minimum Effort Grid Path

Minimum Effort Grid Path

Hard
Coding
Asked at 1 company1ArraysHash TablesDynamic Programming
Also asked at
University of Cincinnati

Problem

Find the minimum possible effort to move from the top-left to the bottom-right of a height grid. Moving between adjacent cells costs the absolute height difference, and the effort of a path is the maximum such difference along that path.

Examples

Example 1
Inputheights = [[1,2,2],[3,8,2],[5,3,5]]Output2WhyThe optimal path avoids the steepest jump and keeps the maximum step cost at 2.
Example 2
Inputheights = [[1,2,3],[3,8,4],[5,3,5]]Output1WhyA longer route can still be better if it minimizes the largest adjacent difference.

Constraints

  • 1 <= m, n <= 100
  • 1 <= heights[i][j] <= 10^6
  • Moves are allowed only in four directions

Problem

Find the minimum possible effort to move from the top-left to the bottom-right of a height grid. Moving between adjacent cells costs the absolute height difference, and the effort of a path is the maximum such difference along that path.

Examples

Example 1
Inputheights = [[1,2,2],[3,8,2],[5,3,5]]Output2WhyThe optimal path avoids the steepest jump and keeps the maximum step cost at 2.
Example 2
Inputheights = [[1,2,3],[3,8,4],[5,3,5]]Output1WhyA longer route can still be better if it minimizes the largest adjacent difference.

Constraints

  • 1 <= m, n <= 100
  • 1 <= heights[i][j] <= 10^6
  • Moves are allowed only in four directions
Practice Python
Python 3.10
Open on desktop for the full Python editor with syntax highlighting and autocomplete.