Given a non-empty grid of non-negative integers, return the minimum path sum from the top-left to the bottom-right cell using only right and down moves. Pattern focus: Space optimization. Reduce the standard 2D DP table to a single row while preserving correctness.
grid is a non-empty matrix of non-negative integers
minimum path sum
Example 1:
Input:
grid = [[1,3,1],[1,5,1],[4,2,1]]
Output:
7
Explanation:
The minimum cost remains 7 even when solved with a rolling array.
Example 2:
Input:
grid = [[1,2,3],[4,5,6]]
Output:
12
Explanation:
The minimum sum is 12.
Example 3:
Input:
grid = [[5]]
Output:
5
Explanation:
A single cell still returns 5.