Minimum Falling Path Sum
Problem statement
Given a rectangular integer matrix, choose any cell in the top row. On each next row, move down-left, straight down, or down-right.
Return the minimum sum of a path that reaches the final row.
Function
minimumFallingPathSum(matrix: int[][]) → longExamples
Example 1
matrix = [[2,1,3],[6,5,4],[7,8,9]]return = 13The path 1 → 5 → 7 has sum 13.
Example 2
matrix = [[-19,57],[-40,-5]]return = -59Choose -19, then move down to -40.
Example 3
matrix = [[5]]return = 5The only cell is both the top and final row.
Constraints
1 <= matrix.length, matrix[i].length <= 1000.- All rows have the same length.
-1000000000 <= matrix[i][j] <= 1000000000.- The answer fits in a signed 64-bit integer.