Data Structures & AlgorithmsVery hardICPC regional · CAT · MBA placement

Problem: For the word-count test: how many distinct strings can be formed by rearranging "AABBCCD" so that no two identical letters are adjacent?

  1. A. 630
  2. B. 246
  3. C. 90
  4. D. 270

Correct answer: B. 246

Inclusion–exclusion over the pairs AA, BB, CC: 630 − 3·180 + 3·60 − 24 = 246, matching a brute force. Ignoring the restriction gives 630, stopping after subtracting single glued pairs gives 90, and forgetting the final −24 term gives 270.

More Coding Interview Problems questions

Exams that ask this topic