6 kyu

Climbing Stairs

222 of 471saudiGuy

Description:

Task

A staircase is given with a non-negative cost per each step. Once you pay the cost, you can either climb one or two steps. Create a solution to find the minimum sum of costs to reach the top. You can start at either of the first two steps.

Examples

Stairs: [0, 2, 2, 1]
Step 0: Start on first step
Step 1: Pay 0 and climb two steps to reach the third step
Step 2: Pay 2 and climb two steps to reach the top
Total spent: 2

Stairs: [0, 2, 3, 2]
Step 0: Start on first step
Step 1: Pay 0 and climb two steps to reach the third step
Step 2: Pay 3 and climb two steps to reach the top
Total spent: 3

Stairs: [10, 15, 20]
Step 0: Start on the second step
Step 1: Pay 15 and climb two steps to reach the top
Total spent: 15

Stairs [0, 0, 0, 0, 0, 0]
Take any path, because every step is free!

Stairs [0, 1, 2, 0, 1, 2]
Step 0: Start on the second step
Step 1: Pay 1 and climb two steps to reach the fourth step
Step 2: Pay 0 and climb one step to reach the fifth step
Step 3: Pay 1 and climb two steps to reach the top
Total spent: 2

Notes

  • 2 <= number of steps <= 1000
Logic
Algorithms
Dynamic Programming

Stats:

CreatedJul 19, 2023
PublishedJul 19, 2023
Warriors Trained1268
Total Skips50
Total Code Submissions1479
Total Times Completed471
Python Completions222
JavaScript Completions122
C++ Completions127
TypeScript Completions20
PHP Completions18
CoffeeScript Completions8
Haskell Completions4
Total Stars26
% of votes with a positive feedback rating88% of 82
Total "Very Satisfied" Votes67
Total "Somewhat Satisfied" Votes11
Total "Not Satisfied" Votes4
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • saudiGuy Avatar
  • SagePtr Avatar
  • dfhwze Avatar
  • tobeannouncd Avatar
  • 66  Avatar
Ad