dsa · easy
Min Cost Climbing Stairs
GreyOrangeDynamic ProgrammingFoundation
You can start at index 0 or 1. From i you pay cost[i] and climb 1 or 2 steps. Return the min cost to reach the top (past the last index).
Arguments
cost— the cost array;cost[i]is the cost of step i
**Example:** [10,15,20] → 15.
Constraints
2 <= cost.length <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [10,15,20] Expected: 15
Example 2
Input: [1,100,1,1,1,100,1,1,100,1] Expected: 6