Minimal Path Sum

Find the minimal path sum from the top left to the bottom right of a 2D grid by only moving right or down.

Medium1/4/2024

Problem statement

Given a 2D square grid of positive integers, write a function to find the minimal sum of a path from the top left corner to the bottom right corner. You can only move to the right or down. Input will be a 2D array of integers, and output should be the minimal sum.

For instance, given the following grid:

[
  [1, 3, 4],
  [1, 5, 2],
  [4, 4, 1],
]

The minimal path sum is 10 (1 -> 1 -> 5 -> 2 -> 1).

Problem leaderboard

#
Size
%
Users
#1
53 c.
Top 5%
lydxn
#2
68 c.
Top 11%
helbling
#3
82 c.
Top 16%
oskar
#4
83 c.
Top 21%
Lv0Sys
#5
86 c.
Top 32%
voytxt
Shanethegamer
#6
87 c.
Top 37%
XenThe
#7
99 c.
Top 42%
targrik
#8
114 c.
Top 47%
Thomasdcrt
#9
115 c.
Top 53%
AlephSquirrel
#10
131 c.
Top 58%
mathis
#11
132 c.
Top 63%
scpchicken
#12
145 c.
Top 68%
Alex
#13
168 c.
Top 74%
SephQ
#14
175 c.
Top 79%
ComputerKWasTaken
#15
209 c.
Top 89%
Natanaelel
val
#16
252 c.
Top 95%
maximec-indy
#17
276 c.
Top 100%
CorentinTh