Minimum Path Sum
Problem Statement
Every cell of an m × n grid holds a cost (a number that is never negative). Start at the top-left cell and walk to the bottom-right cell, moving only down or right. Every cell on the path adds its cost to the total, including the start and the end.
Return the smallest total that any path can reach.
grid, an m × n grid of non-negative numbers.
The smallest sum of the costs along a path from the top-left cell to the bottom-right cell.
The path 1 → 3 → 1 → 1 → 1 (Right, Right, Down, Down) adds up to 7. No other path is cheaper.
There are three paths. The cheapest is 1 → 2 → 3 → 6 (Right, Right, Down), which adds up to 12.
- • 1 ≤ m, n ≤ 200
- • 0 ≤ grid[i][j] ≤ 200
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
The cheapest total into a cell is its cost plus the cheaper of the cells above and to the left
dp[r][c] = grid[r][c] + min(dp above, dp left), filled one cell at a time
row[c] = grid[r][c] + min(row[c] above, row[c − 1] to the left), updated in place
Let cost(r, c) be the cheapest total of a path from the top-left to (r, c), including (r, c). The path must enter (r, c) from above or from the left, so cost(r, c) = grid[r][c] + min(cost(r−1, c), cost(r, c−1)). The start costs only its own value.
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.