FunctionRacerProblemsRace

Stacked Cans

BeginnerDynamic programmingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems