Minimize the Steepest Step on a Grid Route

Quick Overview

Minimize the Steepest Step on a Grid Route. Travel from the top-left to the bottom-right cell of heights, moving only between side-adjacent cells. The effort of a route is the largest absolute height change on any step.

Minimize the Steepest Step on a Grid Route

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Travel from the top-left to the bottom-right cell of `heights`, moving only between side-adjacent cells. The effort of a route is the largest absolute height change on any step. Return the smallest achievable effort. ```cpp class Solution { public: int minimumEffortPath(vector<vector<int>>& heights); }; ``` ### Examples **Example 1:** ```text heights = [[2,6],[3,4]] Output: 1 Explanation: Follow heights 2 -> 3 -> 4, with step differences 1 and 1. ``` **Example 2:** ```text heights = [[9,1,8]] Output: 8 Explanation: The only route has step differences 8 and 7. ``` ### Constraints - `rows == heights.length`, `columns == heights[i].length`. - `1 <= rows,columns <= 100`. - Heights are integers in `[1,10^6]`. ### Clarifying Questions Minimize the maximum edge difference, not the sum of differences. A route consisting of a single cell has effort zero. ```hint Inspect the structure How do you compare two route efforts when several small steps compete with one large step? ``` ### Reasoning checkpoints - Compare route effort using its largest step change rather than a sum. - Prove that no alternative route has a smaller effort, including equal-height and one-cell cases. ### Optional extensions How would a threshold reachability check support binary search for the same answer?

Overview: Minimize the Steepest Step on a Grid Route. Travel from the top-left to the bottom-right cell of heights, moving only between side-adjacent cells. The effort of a route is the largest absolute height change on any step.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Travel from the top-left to the bottom-right cell of heights, moving only between side-adjacent cells. The effort of a route is the largest absolute height change on any step. Return the smallest achievable effort.

class Solution {
public:
    int minimumEffortPath(vector<vector<int>>& heights);
};

Examples

Example 1:

heights = [[2,6],[3,4]]
Output: 1
Explanation: Follow heights 2 -> 3 -> 4, with step differences 1 and 1.

Example 2:

heights = [[9,1,8]]
Output: 8
Explanation: The only route has step differences 8 and 7.

Constraints

  • rows == heights.length , columns == heights[i].length .
  • 1 <= rows,columns <= 100 .
  • Heights are integers in [1,10^6] .

Clarifying Questions Guidance

Minimize the maximum edge difference, not the sum of differences. A route consisting of a single cell has effort zero.

Reasoning checkpoints

  • Compare route effort using its largest step change rather than a sum.
  • Prove that no alternative route has a smaller effort, including equal-height and one-cell cases.

Optional extensions

How would a threshold reachability check support binary search for the same answer?