Problem: How many rearrangements of the letters of $HMMTHMMT$ do not contain the substring $HMMT$? (For instance, one such arrangement is $HMMHMTMT$.) Solution: The answer is $361$. If $A$ is the set of all rearrangements that do not contain the substring $HMMT$, we deploy complementary counting by observing $|A| = |\{ \text{All permutations of } HMMT\}| - |\{ \text{All permutations that do contain } HMMT \}| $The former set on the RHS is just $\frac{8!}{2!2!4!} = 420$ (there are two $Ts and two $Hs and four $Ms) Consider treating the substring $HMMT$ as one object, $K$. Computing the size of the latter set is identical to computing all permutations of the string $KHMMT$ which is just $\frac{5!}{2!}$. However, we count the case of $HMMTHMMT$ twice, so the latter set on the RHS is just $\frac{5!}{2} - 1 = 59$. Thus, the answer is $420 - 59 = 361$.