easy1-D Dynamic ProgrammingAmazonMicrosoft
Treadmill Ticket Cheapskate
A gym chain charges a per-step entry fee; a budgeter wants the minimum total toll to pass through to the top floor using 1- or 2-step hops.
Given a cost array where cost[i] is the fee for using step i, you can start at index 0 or 1. From each step hop 1 or 2 forward. Return the minimum total cost to reach the top.
Choose approach
0
00
1?
2?
3i
1/4
Narrationstep 1 of 4
Base: dp[0] = dp[1] = 0 (free entry from the ground).
Variables
How to think about it
- Pay only when you land on a step (except the top).
- Two choices for each landing.
Edge cases to catch in interview
- n = 2 -> min(cost[0], cost[1]).
- Alternating big/small costs stress the min.
Examples
Example 1
6{"cost":[1,100,1,1,1,100,1,1,100,1]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed