Counting the number of words made of $2n$ letters 
Compute the number of words made of $2n$ letters taken from the alphabet $\{a_1, a_2,\ldots,a_n\}$ such that each letters occurs exactly twice and no two consecutive letters are equal.

I started first of all thinking about the possibilities when we are not restricted by the fact that two consecutive letters are equal. Because we need to choose $2n$, and letters occur exactly twice, so that we can permute each letter pair $2!$ times, we will have something like this: $$\frac{2n!}{(2!)^n} = \frac{2n!}{2^n}$$
Now, I have to somehow exclude the possibilities when two consecutive letters are equal. I was stuck here, then I came across the answer to the problem (which I assume is the same problem), from Putnam and Beyond, page 326 in the PDF, and 309 of the book. I see that he has used inclusion-exclusion principle, but I didn't quite get how the numbers were obtained. Any explanation of that answer, or another solution is highly welcomed.

The strategy taken is to find the total number ways to arrange the letters $-$ the total number of ways to arrange the letter such that at least one pair of letters are together.
The total number of ways to arrange the letter as you have found is: $$\frac{(2n)!}{2^n}$$
Let $A_i$ be the number of ways to arrange the $2n$ letters such that $i^{th}$ pair are together. Therefore, we need to find: 
$$|\overline{A_1 \cup A_2 \cup \dots \cup A_n}|=\frac{(2n)!}{2^n}-|A_1 \cup A_2 \cup \dots \cup A_n|$$
$\sum_{i=1}^n|A_i|$ is the number of ways to arrange the letters with any $1$ pair together and is given by: 
$$\binom{n}{1}\frac{(2n-1)!}{(2!)^{n-1}}$$ 
This is because we arrange the remaining $2n-2$ letters and the $1$ grouped pair. After which we divide by $(2!)^{n-1}$ as there are $n-1$ remaining pairs.
Next, we have to find $\sum_{1 \leq i,j \leq n} |A_i \cap A_j|$, the case when any two pairs are together. Using a similar argument, we have:
$$\binom{n}{2}\frac{(2n-2)!}{(2!)^{n-2}}$$
Extending this to the $k^{th}$ case, to find $\sum_{1 \leq i,j \dots,k \leq n} |A_i \cap A_j\dots \cap A_k|$ we can extend the formula to:
$$\binom{n}{k}\frac{(2n-k)!}{(2!)^{n-k}}$$
Using the inclusion and exclusion principle, 
$$|\overline{A_1 \cup A_2 \cup \dots \cup A_n}| =\frac{(2n)!}{2^n}-\sum_{i=1}^n|A_i|+\sum_{1 \leq i,j \leq n} |A_i \cap A_j|-\sum_{1 \leq i,j \dots,k \leq n} |A_i \cap A_j\dots \cap A_k|$$
$$\quad \quad \quad \quad \quad =\frac{(2n)!}{2^n}-\binom{n}{1}\frac{(2n-1)!}{(2!)^{n-1}}+\binom{n}{2}\frac{(2n-2)!}{(2!)^{n-2}}+\dots+(-1)^k\binom{n}{k}\frac{(2n-k)!}{(2!)^{n-k}}$$
$$=\sum_{k=0}^n(-1)^k\binom{n}{k}\frac{(2n-k)!}{(2!)^{n-k}}$$
