How many words with four letters can be formed if each letter could be used maximum $2$ times? 
You have the five letters $A, B, C, D$ and $E$. How many words with four letters can be formed if each letter could be used a maximum of $2$ times? (a letter appears in the word $0, 1$ or $2$ times.)

I have tried $5\cdot4\cdot3\cdot3$ and then thought that the positions can be arranged in $4\cdot3\cdot2\cdot1$. However, this should be divided by $2$ because $A~A~\_~\_$ and $A~A~\_~\_$ are the same results. But the answer I got was not correct. The correct answer according to the key is $540$.
 A: With $5$ letters, you can make $5^4$ four-letter words.
But among these words,

*

*there are the ones with one letter which is repeated four times (there are obviously $5$ such words);

*and there are the words with a letter repeated three times. There are $5 \times 4 \times 4$ such words (indeed you have to choose the triple letter - $5$ possibilities, the other letter - $4$ possibilities left, and finally the place of the other letter - $4$ possibilities).

So the total number of words you want to count is
$$5^4 - 5 - 5\times 4 \times 4 = 540$$
A: There are three cases possible.
1. All letters are distinct
Like ($A, B, C, D$). Selecting $4$ letters out of $5$ and arranging them gives $\displaystyle{5\choose 4}\cdot 4!=120$ ways.
2. Two distinct and two same
(Like $A,B,C,C$). Selecting $3$ letters out of $5$ and again selecting one from those $3$ letters as the fourth letter and arranging them: $\displaystyle{5\choose 3}\cdot{3\choose 1}\cdot\frac{4!}{2!}=360$ ways.
3. Only two distinct letters
(Like $A,A,C,C$). Selecting $2$ letters out of $5$ letters and arranging gives $\displaystyle{5\choose 2}\cdot\frac{4!}{2!\cdot2!}=60$ ways.
Adding all these give us $540$.
