How many ternary strings (that is, strings made up of 0s, 1s and 2s) of length 5 contain atmost two 0s, at most two 1s and at most two 2s?

There are 3 basic categories here, as there has to be at least one of one number, and two of the other two numbers. So we have:

$$\text{01122}$$
$$\text{10022}$$
$$\text{20011}$$

So I take each these and permutate. Which gives me $$3 \times 5!$$ which is wrong. The answer is $$90$$. I know it is wrong because $$3 \times 5! > 3^5$$ which shouldn't be possible. I can't find any intuitive reason why my answer is wrong.
How did I approach it wrong?

• There aren't $5!$ permutations of, say, $01122$. – lulu Jun 20 '19 at 0:33

There are some repeated bits (like $$1$$'s and $$2$$'s in the first category). So you can't permute them with $$5!$$ since swapping $$1$$'s or $$2$$'s in the first category doesn't change the string, similar in the second and the third category. Therefore, your answer should be $$3\cdot\frac{5!}{2!2!} = 90$$