107. Minimum Path Sum

MediumArrayArray

Given a m x n grid filled with non-negative numbers, find a path from top-left to bottom-right that minimizes the sum of all numbers along its path. You can only move right or down.

Input: A 2D non-negative integer array grid of size m x n.

Output: Integer — minimum path sum from top-left to bottom-right.

Examples

Example 1
Input: [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: Path 1→3→1→1→1=7.
Example 2
Input: [[1,2,3],[4,5,6]]
Output: 12
Explanation: Path 1→2→3→6=12.
Example 3
Input: [[1]]
Output: 1
Explanation: Single cell.

Constraints

Asked by

MicrosoftAmazonInfosysGoogleBloombergMeta
Solve this problem in the editor →