Cheapest path down a triangle
A triangle of integers is given as rows, where row i holds i + 1 numbers. A path starts at the single number on top and moves down one row at a time, from position j to position j or j + 1 of the next row, until it reaches the bottom row. Return the smallest sum that a path can have.
The triangle has 1 to 200 rows, with values between −10,000 and 10,000. Aim for O(n) extra space, where n is the number of rows.
Besides the tests, one large input (a triangle of 23 rows) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
cheapest_path([[1],[2,3],[9,9,1],[9,9,9,1]])→6cheapest_path([[4],[1,6],[7,2,5]])→7cheapest_path([[-3]])→-3