19. Path With Minimum Effort
β GFG solution to the Path With Minimum Effort problem: find minimum cost path where cost is maximum absolute difference between consecutive cells using Dijkstra's algorithm. π
π§© Problem Description
π Examples
Example 1
Input: mat[][] = [[7, 2, 6, 5],
[3, 1, 10, 8]]
Output: 4
Explanation: The route of [7, 3, 1, 2, 6, 5, 8] has a minimum value of maximum absolute
difference between any two consecutive cells in the route, i.e., 4.Example 2
Input: mat[][] = [[2, 2, 2, 1],
[8, 1, 2, 7],
[2, 2, 2, 8],
[2, 1, 4, 7],
[2, 2, 2, 2]]
Output: 0
Explanation: The route of [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] has a minimum value of
maximum absolute difference between any two consecutive cells in the route, i.e., 0.π Constraints
β
My Approach
Dijkstra's Algorithm with Modified Cost
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated