FastPrepMaximum Falling Path Sum
Problems/Maximum Falling Path Sum

Maximum Falling Path Sum

AMD logoAMD● MediumNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Maximum Falling Path Sum and compares it with the minimum variant. The rectangular shape, three allowed downward moves, bounds and interface are authored; approximate source match 85%. An exact source date is not available.

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[][]) → int

Examples

Example 1

matrix = [[2,1,3],[6,5,4],[7,8,9]]return = 17

The path 3 → 5 → 9 uses adjacent columns and totals 17.

Example 2

matrix = [[-5,-2],[-3,-4]]return = -5

The 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.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int maxFallingPath(int[][] matrix) {
    // Write your code here.
}
Checking account…