Four-letter strings from the set $S = \{A, B, C, D, D, D, E, E, F, G\}$ with a few conditions Consider the set $S = \{A, B, C, D, D, D, E, E, F, G\}$. How many different four-letter strings can be built using elements of $S$ such that no two adjacent letters in the string are the same $\textit{and}$ the first and last letters are different? Each element of the set can only be used once.
 A: Let $A$ be the number of the strings which has at least one pair of adjacent same letters. 
Also, let $B$ be the number of the strings whose first letter and the last letter are the same.
Also, let $C$ be the number of the strings which has at least one pair of adjacent same letters and whose first letter and the last letter are the same.
So, what you want is 
$$\frac{10!}{3!2!}-(A+B-C).$$
In the following, note that $X\not=Y$ and that $X\not=D, X\not=E, Y\not=D, Y\not=E.$
1) For $A$, we have the following patterns :
$$\{DDDE\},\ \{DDDX\}\ \{DDEE\},\ DDEX, EDDX, $$$$XDDE, EXDD, XEDD,\ DDXY, XDDY, XYDD,\ EEXY, XEEY, XYEE.$$
Note that $\{\}$ means a set.
2) For $B$, we have the following patterns :
$$DEED, \ DEXD, \ DXED,\ \ DXYD,\ EDDE,\ EDXE,\ EXDE, \ EXYE.$$
3) For $C$, we have the following patterns :
$$DDED,\ DEDD,\ DDXD,\ DXDD,\ DEED, \ EDDE.$$
A: Here you have $7$ symbols. They are as follows.
$A$ once, $B$ once, $C$ once, $D$ thrice, $E$ twice, $F$ once, $G$ once.  
You want to fill $4$ position by them.
First position can be filled by $7$ ways.
Last position will be different from the first. So we can fill it in $6$ ways. 
The second position will be different from the first and last (as we shall use any element of the set only once). So we can fill it in 5 ways.
Third position will be different from the second and last (fourth) and will also be different from the first (as we may use any element of the set only once). So we may select it in 4 ways.
So total number will be $7 \times 6 \times 5 \times 4$
