Given a grid of non-negative costs, return the minimum total cost required to travel from the top-left cell to the bottom-right cell, moving only in four directions. Pattern focus: Weighted shortest path. The cost accumulates as you move, so shortest path logic must consider edge weights explicitly.
grid = non-negative cost grid
minimum path cost from start to end
Example 1:
Input:
grid = [[1,3,1],[1,5,1],[4,2,1]]
Output:
7
Explanation:
The cheapest route avoids the larger costs.
Example 2:
Input:
grid = [[1,2,3],[4,5,6]]
Output:
12
Explanation:
The path cost is the sum of the chosen cells.
Example 3:
Input:
grid = [[5]]
Output:
5
Explanation:
A single cell contributes its own cost.