Minimum Falling Path Sum
MediumDynamic Programming2d dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an n x n integer grid matrix. A falling path picks one cell in the first row, then one cell in each following row, where the cell chosen in row r + 1 is in the same column as, or one column left or right of, the cell chosen in row r.
Return the minimum sum of a falling path.
Examples
Input: matrix = [[2,1,3],[6,5,4],[7,8,9]]
Output: 13
The path 1 -> 5 -> 7 (or 1 -> 4 -> 8) sums to 13.
Input: matrix = [[-19,57],[-40,-5]]
Output: -59
The path -19 -> -40 sums to -59.
Constraints
- n == matrix.length == matrix[i].length
- 1 <= n <= 100
- -100 <= matrix[i][j] <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.