char ary[10] = "AAABB";
There are 6!/(3!*2!) possible ways to arrange them. How do I find them all?
char ary[10] = "AAABB";
There are 6!/(3!*2!) possible ways to arrange them. How do I find them all?
First, there are 5! / (3! * 2!) = 10 possible ways, not 6! / (3! * 2!). But I think this is your typo.
For this specific string "AAABB", you can do something like this:
Take away "BB", and treat "A"s as separators of "B" slots. Let _ (underscore) be the slot we can insert "B" in.
_A_A_A_
First, treat "BB" as two separated char, and insert them in. We can insert them in slot 1 & 2 ("BABAA"), 1 & 3 ("BAABA"), 1 & 4, 2 & 3, 2 & 4, 3 & 4. (6 in total)
Then, treat "BB" as one, and insert it in. We can insert it in slot 1 ("BBAAA"), 2 ("ABBAA"), 3, 4. (4 in total)
All 10 possible ways iterated.