Climb stairs
EasyYou're climbing a staircase with
n steps. You can take 1 or 2 steps at a time.Write a function that returns how many distinct ways you can reach the top.
Order matters.
1 then 2 is different from 2 then 1.For example,
n = 3 has 3 ways:1 + 1 + 11 + 22 + 1
n = 1 has 1 way. n = 2 has 2 ways.The starter uses the right idea, but the loop is off by one.
n = 1 still passes. Run it first.Try it first
Solution
7 Essential DSA in the AI era Coding Interview Problems
Master DSA in the AI era by trying the coding challenges below.
- 1.Count occurrencesEasy
- 2.Fix the default listEasy
- 3.Move zeroesEasy
- 4.Is subsequenceEasy
- 5.First unique characterEasy
- 6.Group anagramsMedium
- 7.Climb stairsEasy
