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

0% completed

Path With Minimum Effort (medium)

Problem Statement

You are 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.

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

Examples

Example 1:

  • Input: heights =

.....

.....

.....

Like the course? Get enrolled and start learning!