ProgrammingVery hardTCS NQT · Infosys

Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) + W(n-2) with W(0) = 1 and W(1) = 1. What is W(10)?

  1. A. 55
  2. B. 34
  3. C. 144
  4. D. 89

Correct answer: D. 89

The values run 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, so W(10) = 89. The iterative loop computes the same values with O(1) memory.

More C Programming questions

Exams that ask this topic