← Back to challenges

Climbing Stairs

JavaScriptHardarrayscontrol_flowlogicloops

Instructions

A staircase is given with a non-negative cost per each step. Once you pay the cost, you can either climb one or two steps. Create a solution to find the minimum sum of costs to reach the top (finishing the payments including cost[-2] or cost[-1]). You can either start at cost[0] or cost[1].

Examples

climbingStairs([0, 2, 2, 1]) ➞ 2

climbingStairs([0, 2, 3, 2]) ➞ 3

climbingStairs([10, 15, 20]) ➞ 15

climbingStairs([0, 0, 0, 0, 0, 0]) ➞ 0

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.