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.
Post a Comment for "Count Number Of 0s From [1,2,....num]"