Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

161. Min Cost Climbing Stairs

EasyDay 47 of 60Dynamic Programming

You are given an array cost where cost[i] is the price of stepping on stair i. After paying for a stair you may climb one or two stairs. You can start on stair 0 or stair 1 for free. Return the minimum total cost to reach the top, which is the position just past the last stair.

Example 1
Input: cost = [10,15,20]
Output: 15
Start on stair 1, pay 15 and climb two stairs to the top.
Example 2
Input: cost = [1,100,1,1,1,100,1,1,100,1]
Output: 6
Step only on the stairs that cost 1, skipping every 100.
Constraints
  • 2 <= cost.length <= 1000
  • 0 <= cost[i] <= 999
Hints
Frequently asked at: Amazon, Adobe, Accenture
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min