Maximum Falling Path Sum
Problem statement
Choose one cell in the first row of matrix. Move to the next row each time, either in the same column or one column left or right, staying inside the matrix. Return the largest sum of a complete path ending in the last row. Every path must include exactly one cell per row, even when all values are negative.
Function
maxFallingPath(matrix: int[][]) → intExamples
Example 1
matrix = [[2,1,3],[6,5,4],[7,8,9]]return = 17The path 3 → 5 → 9 uses adjacent columns and totals 17.
Example 2
matrix = [[-5,-2],[-3,-4]]return = -5The path -2 → -3 totals -5, which beats the other complete paths.
Constraints
1 <= matrix.length <= 40.1 <= matrix[r].length <= 40.-10000 <= matrix[r][c] <= 10000.- Every row has the same number of columns.