As reported: Amazon SDE-1 new-grad loop (Bangalore, January 2025), interview 2 — a variation of Maximum Falling Path Sum asking for the minimum falling path sum, followed by a Rotting Oranges variation.
This is LeetCode 931 — Minimum Falling Path Sum.
Given an n × n integer matrix, return the minimum sum of a falling path: start at any cell of the first row, and from (row, col) move to (row + 1, col − 1), (row + 1, col) or (row + 1, col + 1), until the last row.
Example 1
matrix = [[2,1,3],[6,5,4],[7,8,9]]
Output: 13 (1 → 5 → 7 or 1 → 4 → 8)
Example 2
matrix = [[-19,57],[-40,-5]]
Output: -59
Constraints: 1 ≤ n ≤ 100; −100 ≤ matrix[i][j] ≤ 100.
Code runner format: LeetCode's test-case format — matrix on one line. Implement minFallingPathSum(matrix); the harness prints the sum.