Arrange letters to avoid consecutive positions Given 7 letters: a,a,b,b,c,d,e, how many possible ways are there for us to arrange them so that matching letters are not in consecutive positions? (e.g. aabcdbe) is not legal.
I tried to solve the question by finding the total possible ways first. If there's no restriction, then there're $\frac{7!}{2!2!}$ ways. Here we don't want $aa$ and $bb$ appear in the string, so we need to subtract $2\cdot\frac{6!}{2!}$ from $\frac{7!}{2!2!}$. Is that right? Did I miss any unwanted cases? Thanks for the help!
 A: Please apply Principle of Inclusion Exclusion as we discussed in comments. Alternatively, given the number of letters is small, you can also count them as follows -
First place c, d, e as  _ c _  d _ e _ and so there are $4$ places for next letter. Now let's place a
Case $1$: both a are separated. So we choose two places for them. That is ${4 \choose 2} = 6 \ $ ways. That gives us $6$ places to choose from for two b and that is ${6 \choose 2}$ ways. We can then permute c d e in $3!$ ways.
So total number of permissible arrangements = $ \displaystyle {4 \choose 2} {6 \choose 2} 3! = 540$
Case $2$: we place aba together in one of the four places between c d e or to its right or left. After placing the block aba, we now have $5$ places to choose from for the last b.
So total number of permissible arrangements = $ 4 \cdot 5 \cdot 3! = 120$
Adding both cases, we have total of $660$ arrangements.
A: The Laguerre polynomials have some remarkable combinatorial properties and one of them is precisely suited to answer problems of this kind. This is nicely presented in Counting words with Laguerre series by Jair Taylor. We find in section $3$ of this paper:

Theorem: If $m_1,\ldots,m_k,n_1,\ldots,n_k$ are non-negative integers, and $p_{m,n}(t)$ are polynomials defined by
\begin{align*}
  \sum_{n=0}^\infty p_{m,n}(t)x^n=\exp\left(\frac{t\left(x-x^m\right)}{1-x^m}\right)
  \end{align*}
then the total number of $k$-ary words that use the letter $i$ exactly $n_i$ times and do not contain the subwords $i^{m_i}$ is
\begin{align*}
  \int_0^\infty e^{-t}\prod_{j=1}^k p_{m_j,n_j}(t)\,dt
  \end{align*}

Here we consider an alphabet $\{a,b,c,d,e\}$ and words built from the letters $$a,a,b,b,c,d,e$$
Bad words: $\{aa,bb\}$
We have $m_1=m_2=2, n_1=n_2=2$ and we obtain with some help of Wolfram Alpha
\begin{align*}
p_{2,2}(t)&=[x^2]\exp\left(\frac{t\left(x-x^2\right)}{1-x^2}\right)\\
&=[x^2]\left(1+tx+\frac{1}{2}(t-2)tx^2+\cdots\right)\\
  &=\frac{1}{2}t^2-t
\end{align*}
The letters $c,d,e$ contribute according to the paper $t^3$ and it follows
\begin{align*}
\color{blue}{\int_0^\infty e^{-t}\left(\frac{1}{2}t^2-t\right)^2t^3\,dt=660}
\end{align*}
A: Successively apply the well known "gap" and "subtraction" methods.
Keep the $B's$ separate by placing them in the gaps of $-A-A-C-D-E-$ and permute the other letters, thus $\binom62\cdot\frac{5!}{2!} = 900$ ways.
Now subtract arrangements with the $A's$ together treating them as a super $\mathscr A:\;\;-\mathscr A-C-D-E-,\;\;$ i.e. $\binom52\cdot4!= 240$ ways
Thus ans  $= 900-240 = 660$ ways
For small problems, I find this to be the simplest approach
A: Fix $aa$ in one of the $6$ places. Then there are $\frac{5!}{2!}$ arrangements for the rest $5$ letters.
Similarly, fix $bb$ in one of the $6$ places. Then there are $\frac{5!}{2!}$ arrangements for the rest $5$ letters.
There are $5!$ arrangements for $aa$ and $bb$.
Hence, using the inclusion-exclusion principle, the arrangements with $aa$ or $bb$ is:
$$n(aa \text{ or } bb)=n(aa)+n(bb)-n(aa \text{ and } bb)=6\cdot \frac{5!}{2!}+6\cdot \frac{5!}{2!}-5!=600$$
Thus, the final answer is:
$$\frac{7!}{2!2!}-\left(2\cdot \frac{6!}{2!}-5!\right)=1260-600=660.$$
