AlgoFrames

Stair points

Standard · Write code · about 10 min

Step i of a staircase gives points[i] points. You start on step 0, each move climbs 1 or 2 steps, and you must finish on the last step. You collect the points of every step you stand on. Points can be negative.

Return the most points you can collect.

Fill the five slots before you code.

Example 1

Input:

[[4,-3,7,-2,5]]

Output:

16

Walk 0, 2, 4: 4 + 7 + 5. Skipping the negative steps wins.

Example 2

Input:

[[3,8]]

Output:

11

Both steps: you start on step 0 and must end on step 1.

Constraints

  • 1 ≤ points.length ≤ 1,000
  • −1,000 ≤ points[i] ≤ 1,000

Learn the idea first: The DP recipe: state, transition, base cases, order, answer, a visual lesson.

More The DP recipe: state, transition, base cases, order, answer problems