Given an m x n grid of heights, move in four directions from the top-left cell to the bottom-right cell. The effort of a path is the maximum absolute difference between adjacent cells along that path. Return the minimum possible effort. Pattern focus: Prim-style graph traversal on a grid where the path cost is the maximum edge weight seen so far.
heights = grid of non-negative integers
minimum effort needed to travel from top-left to bottom-right
Example 1:
Input:
heights = [[1,2,2],[3,8,2],[5,3,5]]
Output:
2
Explanation:
One optimal route keeps the maximum step difference at 2.
Example 2:
Input:
heights = [[1,2,3],[3,8,4],[5,3,5]]
Output:
1
Explanation:
A path exists where every adjacent height difference is at most 1.
Example 3:
Input:
heights = [[7]]
Output:
0
Explanation:
With a single cell, no movement is needed, so the effort is 0.