Let N be the number of 4 digit numbers formed with atmost 2 distinct digits then last digit of N is?

273 Views Asked by At

My approach - I am arranging the digits in all possible ways first( repetition allowed). This gives me 9*10*10*10=9000 Then I split the problem in two part, Case 1: When all digits are distinct - 9*9*8*7=4536 Case 2: When 3 digits are distinct and the fourth is a selection from the three which gives 9*9*8*3 =1944 Then i subtract these two results from 9000 which gives amswer 2520 so last digit is 0. Where am I wrong? Please help..

2

There are 2 best solutions below

0
On BEST ANSWER

There are $\frac {9*10}2$ possible pairs for the two digits.

For each of the $4$ digits there are $2$ possible choices for which digit it will be.

so there $2^4*\frac {9*10}2 = 720$ ways to do this.

But the first digit cannot be $0$. There $9$ possible pairs were one of the two digits are $0$ and there are $2^3$ ways that the first digit is $0$.

So there are $720 - 9*2^3= 648$ ways to do this.

1
On

The error is in case 2: it assumes that the last digit is a repeat of one of the three others. But the last digit may be unique, and the repeat may be among the first three digits. The correct expression would be $9*9*8*6$, which is $9*9*8$ ways to select all the distinct digits (in order of first occurrence) multiplied by the number of ways to choose which 2 of the 4 digits are equal. The result is $9*10*10*10 - 9*9*8*7 - 9*9*8*6 = 576$.

Confirmed by brute force: sum([len(set(str(n)))<=2 for n in xrange(10**3,10**4)]) in python.

The error in fleablood's answer is that if one of the two selected digits goes unused, it shouldn't matter what that digit is. Can be fixed by separating the one-digit and two-digit cases: $(2^4-2)\frac{9*10}{2} + 9=639 - (2^3-1)*9=576$.