How many numbers between $1$ and $999,999$ inclusive have exactly two of the digits $1, 2, 3$ and $4$ at least once?
I am just not too sure where to start on this one. Does anyone have any hints on how to start using the principle of exclusion and inclusion.
Thanks
We first count all strings of length $6$ over the alphabet $A:=\{x,y,5,6,7,8,9,0\}$ that contain at least one $x$ and at least one $y$. There are $8^6$ strings in all (we don't have to bother about strings beginning with $0$), then $7^6$ strings that do not contain an $x$ and $7^6$ strings that do not contain a $y$; finally there are $6^6$ strings that contain neither $x$ nor $y$. Using inclusion/exclusion we can therefore say that there are $$8^6-2\cdot 7^6+6^6$$ strings of length $6$ over $A$ containing at least one $x$ and at least one $y$. Now from $\{1,2,3,4\}$ we can select ${4\choose2}=6$ pairs $x<y$, and we then can replace $x$ and $y$ in the constructed strings accordingly. It follows that there are $$6\cdot(8^6-2\cdot 7^6+6^6)=441\,012$$ strings of the desired kind.