Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Min Cost Climbing Stairs

Easy
dynamic-programmingarray

cost[i] is the toll for stepping on stair i; after paying you may climb 1 or 2 stairs. You may start at index 0 or 1. Return the minimum cost to reach the top (one past the last stair).

Input: one line of space-separated integers cost. Output: the minimum total cost.

Example 1
Input:
10 15 20
Output:
15

Start at 15, jump to the top.

Example 2
Input:
1 100 1 1 1 100 1 1 100 1
Output:
6

Constraints

  • 2 ≤ cost.length ≤ 1000
  • 0 ≤ cost[i] ≤ 999
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.