Design Gurus Logo
Min Cost Climbing Stairs (easy)

Problem Statement

Given an array of integers cost, where cost[i] represents the cost of the i<sup>th</sup> step on a staircase, determine the minimum total cost to reach the top of the staircase.

It is given that once you pay the cost, you can climb the stairs by either taking one step or two steps at a time. You can start stepping either from the 0 or 1 index.

Examples

  1. Example 1:

    • Input: [2, 7, 9, 3, 1]
    • Expected Output: 10
    • Justification: The minimum cost path starts on the second step (cost=7), then jumps two steps to the fourth step (cost=3), and finally reaches the end, totaling a cost of 10.
  2. Example 2:

    • Input: [3, 2, 10, 1]
    • Expected Output: 3
    • Justification: The minimum cost path is starting on the second step (cost=2) and then jumping two steps to the last step (cost=1), totaling a cost of 3.
  3. Example 3:

    • Input: [5, 10, 5, 15, 10, 5, 20]
    • Expected Output: 25
    • Justification: The optimal path involves taking the first step (cost=5), skipping to the third step (cost=5), then to the fifth step (cost=10), and finally to the sixth step (cost=5), totaling a cost of 25.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory