Logo
Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Path With Minimum Effort

Problem Statement

Given a 2D array heights[][] of size n x m, where heights[n][m] represents the height of the cell (n, m).

Find a path from the top-left corner to the bottom-right corner that minimizes the effort required to travel between consecutive points, where effort is defined as the absolute difference in height between two points. In a single step, you can either move up, down, left or right.

Determine the minimum effort required for any path from the first point to the last.

Example Generation

Example 1:

  • Input: [[1,2,3],[3,8,4],[5,3,5]]

.....

.....

.....

Like the course? Get enrolled and start learning!