Imagine you're climbing a staircase where each step has a toll fee you must pay before moving forward. You're given an integer array cost where cost[i] represents the price to step on the i-th step.
Here's the twist: once you pay the cost for a step, you can either climb one step or two steps forward. You have the flexibility to start your journey from either step 0 or step 1 (both are free to start on).
Goal: Find the minimum cost to reach the "top of the floor" (which is one position beyond the last step in the array).
Example: If cost = [10, 15, 20], you want to reach position 3 (beyond the array). You could start at step 1 (cost 15), then jump 2 steps to reach the top, for a total cost of 15.
Input & Output
Constraints
- 2 β€ cost.length β€ 1000
- 0 β€ cost[i] β€ 999
- You can start from step index 0 or 1
- The "top of the floor" is one position beyond the last array element