A pyramid chart has rows of numbers: row 0 has one number, row 1 has two, and so on. From position i in one row, you may step to position i or i + 1 in the next row.
Write cheapestDescent(rows) that returns the smallest sum of numbers on a path from the top to any number in the bottom row.
Input: rows = [[3],[7,4],[2,4,6],[8,5,9,3]] Output: 16
3 → 4 → 4 → 5, or 3 → 4 → 6 → 3.
Input: rows = [[-10]] Output: -10
A single number.
1 <= rows.length <= 200rows[r].length === r + 1-10000 <= rows[r][i] <= 10000Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #507 Cheapest Path Down a Pyramid Chart. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.