A jeweler lays out a straight strand of colored beads, one bead per position. Beads of the same color are identical and indistinguishable from one another. Given the multiset of bead colors, count how many visually distinct arrangements of all the beads in a row are possible.
Two arrangements are the same only if every position shows the same color in both.
A single line: a string of 1 to 8 lowercase English letters, where each letter is the color of one bead.
A single integer: the number of distinct arrangements of all the beads in a row.
Example 1
Input
aab
Expected
3
Explanation
The three distinct arrangements are aab, aba, and baa.
Example 2
Input
abc
Expected
6
Explanation
All three beads differ, so every one of the 3! = 6 orderings is distinct.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →