Think of it this way. Le’ts say you had three people with their respective names a, a, and b. Person #1’s name is “a”. Person #2’s name is also “a”. Person #3’s name is “b” That is why some are listed twice. They have the same name, but they are different things(people).
For just the test case of “aab” in this challenge, it could be worded as follows:
We have three people: John Doe, John Baker, and Tom Jones
How many different ways can we arrange these three people in a straight line with the restriction that anyone with the same first name can not stand beside each other?
OR worded a little differently:
How many different ways can we arrange these three people in a straight line so that the two people named John can not stand beside each other?