anuptvm wrote:Thanks Anshumishra. Is there another method using Permutations? What is a good general strategy for such problems?
Here is another method (using Combinations, which I read on one of the blogs, and modified for the current question) :-
Since 7 does not occur in 1000, we need to count the number of times 7 occurs when we list the integers from 1 to 999.
Now any integer between 1 and 999 is of the form abc, where 0 ≤ a, b, c ≤ 9.
We first calculate the number of integers in which 7 occurs exactly once.
Now 7 can occur at one place in 3C1 ways and the other 2 places can be occupied by any other 2 digits from 0 to 9 except 7.
Hence number of such integers is 3C1 × 9 × 9 = 243.
Since 7 occurs exactly once in each of them, there will be 243 listings of 7 in such integers.
We next calculate the number of integers in which 7 occurs exactly twice.
The two places in which 7 occurs can be selected in 3C2 ways. The remaining 1 place can be occupied by any other digit from 0 to 9 except 7.
Hence number of such integers is 3C2 × 9 or 27.
Since 7 occurs exactly twice in each of them, there will be 2 × 27 = 54 listings of 7 in such integers.
Lastly we calculate the number of integers in which 7 occurs exactly once.
Now there will be only 1 such integer which is 777 and there are 3 listings of 7 in this integer.
Hence, the total number of times 7 occurs in all integers from 1 to 1000 is 243 + 54 + 3 = 300.
My strategy is you must know the basic way to solve the problem (like the one mentioned here), apart from that if you can find some symmetries that would be awesome (But make sure that the symmetry is there, like it is in current case, that is why I could use the first method as shown in my previous post).
Hope that helps !