Minimum Falling Path Sum
Problem Statement
You are given an n × n matrix of integers. A falling path starts in any cell of the first row. From each cell, it moves to the next row: straight down, or diagonally down-left, or diagonally down-right. It must stay inside the matrix.
Return the smallest sum of any falling path. The path adds up the cells it visits.
matrix, an n × n grid of integers.
The smallest sum of any falling path through the matrix.
The path 1 → 5 → 7 (down from the top middle, then down-left) adds up to 13. The path 1 → 4 → 8 also adds up to 13.
The best path is -19 → -40, which adds up to -59.
- • 1 ≤ n ≤ 100
- • −100 ≤ matrix[i][j] ≤ 100
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Recurse down from each first-row cell, trying the cells below that exist, and keep the smallest total
dp[r][c] = matrix[r][c] + min of the three cells above, filled row by row
One row: each cell takes the smallest of the three old cells above; the old left value is saved in a variable
Let falling(r, c) be the smallest sum of a falling path that starts at (r, c) and reaches the last row. Each cell has up to three children below it, so falling(r, c) = matrix[r][c] + min(...) over the children that exist. Try every start in the first row and keep the smallest.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like DP — Grid translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.