Data Structures & AlgorithmsHardCAT · ICPC regional

Problem: A string of length 5 uses the letters x, y, z. How many such strings contain each of the three letters at least once?

  1. A. 150
  2. B. 147
  3. C. 243
  4. D. 25

Correct answer: A. 150

Inclusion-exclusion: 3⁵ − 3 · 2⁵ + 3 · 1⁵ = 243 − 96 + 3 = 150. Forgetting to add back the 3 single-letter strings gives 147, 243 counts all strings, and S(5,3) = 25 forgets to label the groups.

More Coding Interview Problems questions

Exams that ask this topic