Min Cost Climbing Stairs
You are given an array cost where cost[i] is the fee you pay when you step on stair i. Once you pay, you may climb one or two stairs further. You can begin on stair 0 or stair 1 for free choice of start, and the goal is to get past the last stair — think of "the top" as an imaginary landing one position beyond the end of the array.
Return the minimum total fee to reach the top.
Constraints: 2 <= cost.length <= 1000 and 0 <= cost[i] <= 999.
Examples
- Input:
- cost = [10, 15, 20]
- Output:
- 15
Start on stair 1 and pay 15, then jump two stairs straight to the top. Starting at stair 0 would cost at least 10 + 20 = 30 or 10 + 15 = 25.
- Input:
- cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
- Output:
- 6
Start on stair 0 and always jump two stairs, except one single step to skip both 100s: pay 1+1+1+1+1+1 = 6.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.