Stacked Cans
Cans are stacked in a triangle: the top row has 1 can, the row below it has 2, the next has 3, and so on. A stack with rows rows is a stack with one row less, plus a new bottom row of rows cans.
Return the number of cans in a stack with rows rows. A stack with 0 rows has no cans.
Example 1
rows 4
returns 10
1 + 2 + 3 + 4.
Example 2
rows 1
returns 1
A single can.
Example 3
rows 0
returns 0
No rows, no cans.
Constraints
0 <= rows <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Sum of the Last kBeginner
- Take One, Two or ThreeBeginner
- Three Button CalculatorBeginner
- Broken StairsEasy
- Cheapest Toll RouteEasy
- Evenly Spaced RunsEasy
- Fewest Coins for the FareEasy
- Fill the Sack ExactlyEasy