Leonardo’s Leaps (Stair Case Puzzle)

This is a classic interview puzzle asked in many interviews.
Puzzle :Given N step stair, how many number of ways can you climb if you use either 1 or 2 at a time?
For example for a stair case with 3 steps there are total 3 ways to climb it :
Way 1: 1 single step then a double step
Way 2: 1 double step and then a single step
Way 3: 3 single steps

anikam Expert Asked on 22nd August 2015 in Interview Puzzles.
Add Comment

  • 1 Answer(s)

    The problem is ismply calculating nth fibonacci number .
    Let’s write a simple function numWays(x)
    int numWays(int n){
    if(n<=0)return 0; if(n=1)return 1; if(n==2)return 2; else return numWays(n-1)+numWays(n-2); }

    pnikam Expert Answered on 22nd August 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.
  • More puzzles to try-