Data Structures & AlgorithmsModerateInfosys · Accenture pattern

A climber can take 1 or 3 steps at a time. In how many different ordered ways can a staircase of 7 steps be climbed? (ways(n) = ways(n − 1) + ways(n − 3), ways(0) = 1.)

  1. A. 13
  2. B. 6
  3. C. 9
  4. D. 21

Correct answer: C. 9

ways: n=0:1, 1:1, 2:1, 3:2, 4:3, 5:4, 6:6, 7:9. Counting unordered combinations (how many 3-steps: 0, 1 or 2 → 3 ways) is the trap; 21 is the 1-or-2-step (Fibonacci) count.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic