Data Structures & AlgorithmsHardICPC regional · TCS NQT Digital

Problem: Count the sequences of steps from {1, 2, 5} that sum to exactly 10 (the order of steps matters).

  1. A. 10
  2. B. 128
  3. C. 75
  4. D. 89

Correct answer: B. 128

Ordered sequences satisfy f(n) = f(n − 1) + f(n − 2) + f(n − 5) with f(0) = 1, giving f(10) = 128. Treating the steps as an unordered multiset (coin-change loop order) gives 10, an off-by-one f(9) gives 75, and forgetting the 5-step leaves F(11) = 89.

More Coding Interview Problems questions

Exams that ask this topic