Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many distinct strings can be formed by rearranging the letters of 'aabbc'? Run the code.

Problem: How many distinct strings can be formed by rearranging the letters of 'aabbc'? Run the code.
from itertools import permutations
print(len(set(permutations('aabbc'))))
What is printed?
  1. A. 60
  2. B. 30
  3. C. 120
  4. D. 20

Correct answer: B. 30

The multinomial formula 5! / (2! * 2! * 1!) = 30 counts the distinct arrangements.

More Coding Interview Problems questions

Exams that ask this topic