178. Path With Minimum Effort

Medium · Graph

You are given an m×n grid where each cell contains a height value. You need to find a path from the top-left corner to the bottom-right corner (moving only up, down, left, or right). The 'effort' of a path is defined as the maximum absolute difference in heights between any two consecutive cells along that path. Return the minimum possible effort across all valid paths from top-left to bottom-right.

Examples

Example 1
Input: [[1,2,2],[3,8,2],[5,3,5]]
Output: 2
Explanation: Best path keeps the largest step ≤ 2
Example 2
Input: [[1,2,3],[3,8,4],[5,3,5]]
Output: 1
Explanation: A path of consecutive differences ≤ 1 exists

Constraints