In how many distinct ways can the letters of the word BANANA be arranged?
60. BANANA has 6 letters with A repeated 3 times and N repeated 2 times, so the count is 6! / (3! x 2!) = 720 / 12 = 60.
Explain it simply
If all six letters were different, there would be 6! = 720 arrangements. But swapping the three A's among themselves produces the same word, and so does swapping the two N's. Each distinct word was therefore counted 3! x 2! = 12 times, so divide by 12.
Example
Question: Count the distinct arrangements of BANANA.
- Letters: B (1), A (3), N (2). Total 6.
- Arrangements = 6! / (1! x 3! x 2!) = 720 / (6 x 2) = 60.
Follow-up: how many of these start with B? Fix B first; arrange AAANN in 5! / (3! x 2!) = 10 ways.
const f = n => (n <= 1 ? 1 : n * f(n - 1));
console.log(f(6) / (f(3) * f(2))); // Output: 60
console.log(f(5) / (f(3) * f(2))); // Output: 10The same formula, n! / (p! q! r! ...), counts arrangements of any word with repeated letters, such as MISSISSIPPI: 11! / (4! 4! 2!) = 34,650.
What to say in the interview
"Six letters give 720 orderings if all were distinct, but the three A's and two N's are interchangeable, so I divide by 3 factorial times 2 factorial, giving 60."
Common mistakes
- Answering 720 by ignoring repeats.
- Dividing by 3! + 2! instead of 3! x 2!.