P16 · 2 seconds · 256 MB
Min Path Sum
You are given an `m × n` grid of positive integers. Start at the top-left cell and move only right or down to the bottom-right. Return the minimum sum of any such path. The path includes both endpoints.
function minPathSum(grid) → number
CONSTRAINTS
- 1 ≤ m, n ≤ 200
- 1 ≤ grid[r][c] ≤ 200
Input: grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
Output: 7
1 → 3 → 1 → 1 → 1.
Input: grid = [
[1, 2, 3],
[4, 5, 6]
]
Output: 12
1 → 2 → 3 → 6.
1
2
3
4
5
6
7
8
Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.