You have n tiles, where each tile has one letter printed on it.
Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.
For example, "AAB" results in 8 sequences: "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA"
According to me, the number of sequences should be obtained by the following expression:
(nP1+nP2+...nPn)/(frequency_1! x frequency_2! ...)
which, for the above example would be:
(3P1+3P2+3P3)/(2! x 1!) which is the incorrect answer.
What is the right way to do this?
frequency_k!
's would have been justified by way of the shepherd's principle... that if when counting a scenario you overcounted every case the same number of times you can correct your count by dividing by the number of times you counted each. Here, that did not work. Yes, we counted "$A$" twice (once as "$A_1$" and again as "$A_2$") just as we counted each of the others here twice ("$A_1A_2$" vs "$A_2A_1$") but we did not count "$B$" twice... we only counted it once, so shepherd's principle does not apply. – JMoravitz Jun 16 '22 at 13:52