Skip to content

Instantly share code, notes, and snippets.

@jsmney
Created March 24, 2020 21:59
Show Gist options
  • Save jsmney/48d0acd42e5f2d9b162d608db55b3050 to your computer and use it in GitHub Desktop.
Save jsmney/48d0acd42e5f2d9b162d608db55b3050 to your computer and use it in GitHub Desktop.

Prompt

Given a staircase with a given number of stairs, num, write a function that returns the number of different ways one can climb this set of stairs. A person is able to climb the stairs either one at a time, or skip a step, or a mix of both.

Examples

climbStairs(2); // should return 2: one step at a time (1 + 1), or skip a step (2).
climbStairs(0); // should return 1
climbStairs(1); // should return 1
climbStairs(5); // should return 8
climbStairs(100); // should return 573147844013817200640

Getting Started

Feel free to diagram out yourself how you would go up these steps! There may be a pattern that you can take advantage of in your code. Ask yourself

  • What does it mean to have only 0, 1, 2 steps?
  • What happens when I have 3 steps? 4?

Once you come to a good solution:

  • What happens on large input sizes like 15, or even 1000? Will this program timeout?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment