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
Similar Kata:
Stats:
Created | Jul 19, 2023 |
Published | Jul 19, 2023 |
Warriors Trained | 1268 |
Total Skips | 50 |
Total Code Submissions | 1479 |
Total Times Completed | 471 |
Python Completions | 222 |
JavaScript Completions | 122 |
C++ Completions | 127 |
TypeScript Completions | 20 |
PHP Completions | 18 |
CoffeeScript Completions | 8 |
Haskell Completions | 4 |
Total Stars | 26 |
% of votes with a positive feedback rating | 88% of 82 |
Total "Very Satisfied" Votes | 67 |
Total "Somewhat Satisfied" Votes | 11 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 9 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |