Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Min Cost Climbing Stairs

Easy Acceptance 65.21% Points 20

You are given an integer array cost where cost[i] is the cost of stepping on the ith stair. You can climb either one or two steps at a time, and you may start from either index 0 or index 1.

Your task is to return the minimum cost to reach the top of the staircase (just beyond the last stair).

Examples
Example 1

image Input: cost = [10,15,20]
Output: 15
Explanation: Start at index 1, pay 15, and take two steps to reach the top.

Example 2

image Input: cost = [1,100,1,1,1,100,1,1,100,1]
Output: 6
Explanation: Stepping on indices 0, 2, 3, 4, 6, 7, and 9 gives a total cost of 6.

Example 3

image Input: cost = [0,0]
Output: 0
Explanation: Both stairs cost nothing, so the top is reached at zero cost.

Constraints
    • 2 = cost.length = 105
    • 0 = cost[i] = 999
Hints
    • Hint 1: Consider the minimum cost required to reach each position.
    • Hint 2: For every position, think about the possible ways you could have arrived there.
    • Hint 3: Keep track of only the information that is necessary to determine the next minimum cost.
Topics
Dynamic Programming
Companies
Samsung Sprinklr
Added 16 Aug 2026 65.21% acceptance
Ln 1, Col 1Sign in to save your code
10 15 20
15