Back to DSA

Min Cost Climbing Stairs

easy
Acceptance: 60%
Dynamic Programming

A staircase has steps numbered starting from 0. Each step has an associated toll you must pay to leave it. After paying, you may advance one or two steps. You may begin from step 0 or step 1. Find the lowest total toll to reach the top (one step beyond the last).

Examples

Example 1:
Input:cost = [5,15,25]
Output:15
Explanation: Start at step 1 (pay 15), jump two steps to the top. Total cost is 15.
Example 2:
Input:cost = [2,5,1,3,8,1]
Output:7
Explanation: Pay at steps 0, 2, 3, and 5 for costs 2+1+3+1 = 7.

Hints

00:00
1234567