Loading problem...
You are navigating a staircase where each step has an associated toll fee. The array cost represents these fees, where cost[i] denotes the expense incurred when stepping on the i-th stair. Once you pay the toll at any step, you gain the ability to advance either one step or two steps forward.
Your journey can begin from either the ground level (step index 0) or from the first elevated step (step index 1). Your destination is the landing beyond the final step—essentially, you need to move past the last element of the array.
Determine the minimum total expense required to successfully reach the destination beyond the staircase.
cost = [10, 15, 20]15Starting from step index 1, you pay 15 and leap two steps forward to reach the destination. The minimum total expense is 15.
cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]6Starting from step index 0:
cost = [1, 2, 3, 4, 5]6Starting from step index 0, pay 1 and jump to index 2. Pay 3 and jump to index 4. Pay 5 and leap to the destination. Total: 1 + 3 + 2 = 6. Alternatively, starting from index 1: pay 2, jump to 3, pay 4, reach destination = 6.
Constraints