ProgrammingHardGATE CS · Campus placements

How many ways are there to write 5 as an unordered sum of 1s and 2s?

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: B. 3

The partitions are 1+1+1+1+1, 1+1+1+2 and 1+2+2, so there are 3. A DP over sums gives the same count.

More C Programming questions

Exams that ask this topic