Skip to content
Decoder

Minimum Path Sum

Medium

Problem

Each cell of an m × n grid holds a non-negative cost. Find a path from the top-left to the bottom-right cell, moving only right or down, that has the smallest sum of the cells it visits (including both corners). Return that sum.

Example 1

grid = [[1, 3, 1],

Example 2

        [1, 5, 1],

Example 3

Input
[4, 2, 1]]
Output
7
Why
1 → 3 → 1 → 1 → 1

Example 4

grid = [[1, 2, 3],

Example 5

Input
[4, 5, 6]]
Output
12

Constraints

  • 1 <= m, n <= 200 where the grid is m × n
  • 0 <= grid[r][c] <= 200

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.