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?
- A. 56
- B. 57
- C. 126
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many words of length 6 over a three-letter alphabet {x, y, z} have no two adjacent letters equal?
- How many permutations p of 1, 2, ..., 6 satisfy p[i] ≤ i + 1 for every position i (1-based)?
- How many distinct arrangements of the letters of "aabbcc" have no two adjacent letters equal?
- Count monotone lattice paths from (0, 0) to (3, 3) that move one step right (x+1) or up (y+1) and never touch a point (i, i) with 0 < i <…
- How many arrays of length 4 with entries from {0, 1, 2} have an EVEN total sum?
- Pick one number from each of the lists [4, 9, 2], [7, 3, 8] and [5, 6, 1]. The three picks must sum to at most 14. What is the largest…