FastPrepMaximum Falling Path Sum
Problems/Maximum Falling Path Sum

Maximum Falling Path Sum

IMC Trading logoIMC Trading● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad phone screen. The original interview wording was not given. The author pointed to this task through a linked reference. The linked goal is the maximum sum from top to bottom with three allowed moves. Our version is about 90% the same. We chose the matrix limits, that values can be negative, and the method interface.

You are given an n-by-m integer matrix. A falling path starts at any cell in the first row and must finish in the last row.

From (row, col), move to exactly one cell in the next row: (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1). Every visited cell must remain inside the matrix.

The path sum includes every visited value, including both endpoints. Return the maximum possible sum. A path contains exactly one cell from every row.

Function

maxFallingPathSum(matrix: int[][]) → int

Examples

Example 1

matrix = [[10,10,2,0,20,4],[1,0,0,30,2,5],[0,10,4,0,2,0],[1,0,2,20,0,4]]return = 74
matrix
0123450101020204110030252010402031022004

A path with values 20, 30, 4, 20 has sum 74.

Example 2

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

The path 3, 8, 6 reaches the last row with sum 17.

Example 3

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

The best complete path is -2, -3. Stopping at the first row is not allowed.

Example 4

matrix = [[4],[-9],[2]]return = -3
matrix
0041-922

The only column forces the path 4, -9, 2, whose sum is -3.

Constraints

  • For this exercise, assume 1 <= n, m <= 200.
  • For this exercise, assume -10^6 <= matrix[row][col] <= 10^6.
  • Every row contains exactly m values.
  • The maximum absolute path sum is at most 2 * 10^8, which fits in a signed 32-bit integer.

More IMC Trading Phone Screen questions

  • Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
  • Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
  • Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
  • Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
  • Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
  • Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
  • Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
  • Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
  • Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
  • Poker Suit Expected ProfitPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Find Robots by Blocker DistancesUber · PHONE SCREEN
  • Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREEN
  • Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
  • Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREEN
  • Maximal SquareAirwallex · PHONE SCREEN
  • Maximal SquareSalesforce · PHONE SCREEN
  • Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
  • Grid Paths Around Blocked CellsAdobe · PHONE SCREEN
  • Largest Diamond of Ones in a GridRippling · PHONE SCREEN
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
See IMC Trading hiring insights
Saved
class Solution {
    public int maxFallingPathSum(int[][] matrix) {
        // Write your solution here.
    }
}
Checking account…