<s>[INST] $3$ digits numbers in which digits are repeated. 
Total number of $3$ digit number which can be formed by using the digits $1,2,3,4,3,2,1$

$\bf{My\; Try::}$ Total no. of $3$ digits numbers in which exactly $2$ digits are identical, are
$112,113,114,221,223,224,331,332,334$
So Total numbers of $3$ digits numbers are $\displaystyle \frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}+\frac{3!}{2!}$
So we get sum $ = 27$
And Total no. of $3$ digits numbers in which all digits are distinct,are
$123,124,234,341$
So Total numbers of $3$ digits numbers are $\displaystyle3!+3!+3!+3!=24$
So we get Total $ = 27+24=51.$
Is my solution is right, If not Then how can I calculate It, Thanks
 [/INST] Yes, your solution is correct.  In the second case, you want to find the number of 3 digit numbers with distinct digits where the digits are taken from $\{1,2,3,4\}$. This number is just $P(4,3)=4 \times 3 \times 2 = 24$ because the first digit can be chosen in 4 ways, the second in 3 ways (since the second digit can be any digit except the first digit), and the third digit can be chosen in 2 ways (since it can be any of the four digits available except the two digits chosen for the first and second positions). 
</s>