Given an array cost
where cost[i]
represents the cost of stepping on the i-th stair, your goal is to reach the top of the floor with minimum total cost. You can either start from step 0 or step 1, and at each move, you can climb either 1 or 2 steps.
Task:
Implement a function that returns the minimum cost to reach the top of the floor.
Example:
Input: cost = [10, 15, 20]
Output: 15
Explanation: Start at index 1 with cost 15, then take two steps to the top.
Note:
cost
will have at least two elements.As spring unfolds around us on March 28, use this challenge as an opportunity to refresh your dynamic programming skills and build a solid foundation for more advanced problems!