Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement

In how many ways can 9 identical sweets be given to 4 distinct children so that every child gets at least one sweet?

  1. A. 56
  2. B. 57
  3. C. 126
  4. D. 495

Correct answer: A. 56

Stars and bars: place the people's shares as {items − 1} gaps choose {people − 1} divider positions, giving C(items − 1, people − 1) = C(8, 3). Allowing zero sweets for some children gives C(items + people − 1, people − 1) instead.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic