Stack Bash - Master data structures and algorithms

Climb stairs

Easy
You'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 + 1
1 + 2
2 + 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. 1.Count occurrencesEasy
  2. 2.Fix the default listEasy
  3. 3.Move zeroesEasy
  4. 4.Is subsequenceEasy
  5. 5.First unique characterEasy
  6. 6.Group anagramsMedium
  7. 7.Climb stairsEasy