← All challenges

Triangle Max Path Sum

Grid / Path ★★☆☆

Maximum sum from top of a 10-row number triangle to the bottom row, moving down-left or down-right at each step.

You’re descending a 10-level carnival pyramid. Each booth pays out the dollar amount printed in its cell. Starting at the top booth (row 1), at each step you walk to one of the two booths directly below — straight down (same column) or down-and-right (next column). You collect the payout at every booth you visit, including the top and the one in row 10.

A1:J10 shows the payout layout, flush-left in a 10×10 range (cells above the diagonal are empty). Return the maximum total payout of any descent from row 1 to row 10.

There are 2⁹ = 512 distinct paths. Brute-forcing them by hand is infeasible — the formula has to do the work.

Input

Range A1:J10

ABCDEFGHIJ
1 41
2 82
3 481816
4 159487
5 444835638
6 283261415
7 3339236134642
8 453527152938181
9 491145282218101449
10 2276257232339173
Hint

Branching recursion: at each cell, value plus MAX of two recursive calls — one straight down, one down-and-right. Base case: row past the last.

Solution
=LET(
  tbl, A1:J10,
  fx, LAMBDA(me, ro, co,
    IF(ro > ROWS(tbl),
      0,
      INDEX(tbl, ro, co) + MAX(me(me, ro+1, co), me(me, ro+1, co+1))
    )
  ),
  fx(fx, 1, 1)
)