Data Structures & AlgorithmsHardTCS NQT Digital · ICPC regional

Problem: In how many ways can the number 12 be written as an ordered sum of parts each equal to 1, 2 or 3 (so 1+2+... and 2+1+... are different)?

  1. A. 927
  2. B. 19
  3. C. 233
  4. D. 504

Correct answer: A. 927

Ordered sums follow the tribonacci recurrence f(n) = f(n − 1) + f(n − 2) + f(n − 3) with f(0) = 1, giving f(12) = 927. Counting unordered partitions gives 19, allowing only parts 1 and 2 gives F(13) = 233, and f(11) = 504 is an off-by-one.

More Coding Interview Problems questions

Exams that ask this topic