Skip to content Skip to sidebar Skip to footer

Count Number Of 0s From [1,2,....num]

We are given a large number 'num', which can have upto 10^4 digits ,( num<= 10^(10000) ) , we need to find the count of number of zeroes in the decimal representation starting f

Solution 1:

from0 - 9 : 0 zeros
from10 - 99: 9 zeros ( 10, 20, ... 90)

--100-199 explained-----------------------
100, 101, ..., 109 : 11 zeros (two in100)
110, 120, ..., 199:  9 zeros (this is just the same as10-99) This is important
Total:20
------------------------------------------

100 - 999: 20 * 9 = 180 

total up to999is: 180 + 9: 189
CountZeros('999') -> 189 

Continu this pattern and you might start to see the overall pattern and eventually the algorithm.

Solution 2:

Does the following help you're understanding:

>>>for i inrange(10, 100, 10):...print(CountZeros(str(i)))... 
1
2
3
4
5
6
7
8
9
>>>

What about this:

>>> CountZeros("30")
j Z N F0000

j Z N F0030

j Z N F1030

j Z N F113033

Post a Comment for "Count Number Of 0s From [1,2,....num]"