Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: What is the number of distinct strings of length 4 over the alphabet {a, b} containing at least one 'a' and at least one 'b'?

  1. A. 16
  2. B. 14
  3. C. 6
  4. D. 15

Correct answer: B. 14

2⁴ = 16 strings minus aaaa and bbbb leaves 14. 16 forgets to remove anything, exactly two of each gives C(4,2) = 6, and removing only one uniform string gives 15.

More Coding Interview Problems questions

Exams that ask this topic