1033. Path with Minimum Effort

MediumGraphsShortest PathGridHeap

Given a grid 'heights', a path's effort is the maximum absolute height difference between consecutive cells along it. Return the minimum effort to travel from the top-left cell to the bottom-right cell, moving 4-directionally. The input is JSON {heights}.

Input: JSON {heights}.

Output: Integer — the minimum effort.

Examples

Example 1
Input: {"heights":[[1,2,2],[3,8,2],[5,3,5]]}
Output: 2
Explanation: Route along the right keeps differences <= 2.
Example 2
Input: {"heights":[[1]]}
Output: 0
Explanation: No movement needed.
Example 3
Input: {"heights":[[1,2,3],[3,8,4],[5,3,5]]}
Output: 1
Explanation: A path with max difference 1 exists.

Constraints

Asked by

GoogleAmazonBloombergMicrosoftMeta
Solve this problem in the editor →