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?
- A. 150
- B. 147
- C. 243
- 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
- Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the…
- Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is…
- Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are…
- Problem: From the list of integers [10, 15, 20, 25, 30], remove the elements that are divisible by 4 or by 6 (the rest remain in order)…
- Problem: The number 1729 is written in base 10. What is the sum of its digits in base 12, given as the digit sum of 1729 written in base 12?
- Problem: A sorted list has values 3, 7, 7, 9, 12, 12, 12, 15. How many distinct values lie within the range [7, 12] inclusive?