Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time.
Example 1
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: The path 1 → 3 → 1 → 1 → 1 (right, right, down, down) adds up to 7. Every other path passes through the 5 or the 4 and costs more.
Example 2
Input: grid = [[1,2,3],[4,5,6]]
Output: 12
Explanation: The cheapest path goes right along the top, 1 → 2 → 3, and then down to 6, totalling 12.
Example 3
Input: grid = [[5]]
Output: 5
Explanation: The grid has a single cell, so the path sum is 5.
Since you can only arrive at a cell from above or from the left, the cheapest way to reach it is its own value plus the smaller of those two neighbours' best costs. Fill the dp grid top-left to bottom-right; the bottom-right cell holds the answer.
Run checks all cases above. Submit evaluates all test cases.