Skip to content
BASA DSA

Min Cost Climbing Stairs

Easy1-D Dynamic Programming

cost[i] is the fee for stepping on stair i. Start at stair 0 or 1, then climb one or two stairs each move. Return the minimum fee to reach beyond the last stair.

Example 1

Input
cost = [4,9,2,5]
Output
6

Explanation

Pay 4 at stair 0, jump to stair 2 for 2, then beyond the end, totaling 6.

Example 2

Input
cost = [10,1]
Output
1

Explanation

Start at stair 1 for cost 1 and jump beyond the final stair.

Example 3

Input
cost = [0,0,0]
Output
0

Explanation

All fees are zero, so every valid route costs zero.

Constraints

  • 2 <= len(cost) <= 1000
  • Fees are 0..999

Function contractminCostClimbingStairsArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…