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?- A. 60
- B. 30
- C. 120
- D. 20
Correct answer: B. 30
The multinomial formula 5! / (2! * 2! * 1!) = 30 counts the distinct arrangements.
More Coding Interview Problems questions
- Problem: A 3-person committee is chosen from 6 people. How many committees include at least one of two specific people A or B? Run the…
- Problem: How many non-negative integer solutions (x, y, z) of x + y + z = 10 satisfy x <= 4? Run the code. python print(sum(1 for x in…
- Problem: How many pairs (x, y) with x <= y and x + y = 12 lie in 1..11? Run the code. python print(sum(1 for x in range(1, 12) for y in…
- Problem: How many inversions does the array [4, 3, 2, 1, 0] have? Run the code. python a = [4, 3, 2, 1, 0] print(sum(1 for i in…
- Problem: How many pairs (i < j) of [5, 6, 7, 9, 8] satisfy |ai - aj| = 1? Run the code. python a = [5, 6, 7, 9, 8] print(sum(1 for i in…
- Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code. python print(sum(1 for x in range(1, 501) if x % 3…