35 · Dynamic Programming

#64 Minimum Path Sum

Mediumsolve on LeetCode ↗

frequently reported atGoldman SachsMicrosoftAmazonGoogle

the problem

In plain words

Given an m × n grid of non-negative numbers, find a path from the top-left to the bottom-right (moving only right or down) with the smallest sum of numbers.

in grid = [[1,3,1],[1,5,1],[4,2,1]]

out 7

1→3→1→1→1.

in grid = [[1,2,3],[4,5,6]]

out 12

  • 1 ≤ m, n ≤ 200
  • 0 ≤ grid[i][j] ≤ 200

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #62
      Unique Paths
      Mediumin Dynamic Programming
    2. #120
      Triangle
      Mediumin Dynamic Programming
    3. #1631
      Path With Minimum Effort
      Mediumin Shortest Paths