Data Structures & AlgorithmsHardTCS NQT · CAT

Problem: How many 4-letter strings over {A, B, C} have no letter appearing more than twice?

  1. A. 78
  2. B. 54
  3. C. 81
  4. D. 36

Correct answer: B. 54

Remove strings with a letter at least 3 times: 3 · (4 · 2 + 1) = 27, so 81 − 27 = 54. Removing only AAAA-type strings gives 78, 81 removes nothing, and 36 counts strings using all three letters.

More Coding Interview Problems questions

Exams that ask this topic