Data Structures & AlgorithmsModerateTCS NQT · Product Company SDE

Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?

  1. A. 55
  2. B. 9
  3. C. 81
  4. D. 31

Correct answer: A. 55

f(n) = f(n−1) + f(n−2) + f(n−4) gives 1, 1, 2, 3, 6, 10, 18, 31, 55, so f(8) = 55. Unordered multisets give 9, using steps 1, 2, 3 gives 81, and f(7) = 31 is one index short.

More Coding Interview Problems questions

Exams that ask this topic