Least Steep Hiking Route Across an Elevation Grid
Last updated: November 29, 2026
Quick Overview
Given a grid of elevations, find a path from the top-left to the bottom-right cell moving in four directions that minimizes the largest absolute height difference between consecutive cells. Return that minimum effort.
0
0
0 solved
Given a grid of elevations, find a path from the top-left to the bottom-right cell moving in four directions that minimizes the largest absolute height difference between consecutive cells. Return that minimum effort.
A Google onsite graph question in a Maps hiking-directions frame. It tests whether a candidate can adapt Dijkstra to a bottleneck (minimax) cost, and the interviewer often asks for the binary-search or union-find alternative.
What the Interviewer Expects
- Models cells as graph nodes with edge weight |h1 - h2|
- Adapts Dijkstra to path cost = max edge
- Uses a min-heap keyed by current effort
- Skips stale heap entries
- Mentions binary search plus BFS or Kruskal-style union-find
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Solve it with union-find by sorting edges
- What if diagonal moves are allowed?
- What if some cells are impassable?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: m x n grid of non-negative ints.
- Path cost = maximum |difference| between adjacent steps on the path.
- Output: minimum path cost from (0, 0) to (m-1, n-1)....
High-Level Design
Dijkstra works for any path cost that never decreases as you extend a path. Here extending a path with edge w turns cost c into max(c, w), which is monotone, so the usual greedy holds: the first tim...