Data Structures & AlgorithmsHardICPC regional · TCS NQT

Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?

  1. A. 11
  2. B. 309
  3. C. 628
  4. D. 448

Correct answer: D. 448

f(n) = f(n−2) + f(n−3) + f(n−5) with f(0) = 1 gives f(20) = 448. Unordered multisets give 11, f(19) = 309 is one index short, and f(21) = 628 one too far.

More Coding Interview Problems questions

Exams that ask this topic