Consider strings of 10 digits; there are $10^{10}$ possible such strings.

Among these strings, there are strings that contain sequence(s) of $n$ consecutive zeroes, for $n\le 10$. For example, $$4000000123$$ is one of the strings that contain a sequence of 6 consecutive zeroes.

I am attempting to find how many strings of 10 digits contains $n$ consecutive zeroes.

My early solution is $(m+1)10^m$ where $m=10-n$, which comes from the following consideration.

First, there is only one string that contains 10 consecutive zeroes, i.e.


Next, there are $2\times 10$ strings that contains 9 consecutive zeroes, that is

$$000000000x, x000000000$$

where $x$ can be any digit. And next, there are $3\times 10^2$ string that contains 8 consecutive zeroes:


and so on. Therefore, there are $(m+1)10^m$, $m=10-n$, that contains $n$ consecutive zeroes.

But I am not convinced that this solution is correct. Because for $n=0$, i.e. strings that contain any number, I get $11\times 10^{10}$, which is greater than $10^{10}$, the number all possible strings!

What is the reason of this failure and what is the correct solution?

  • 1
    $\begingroup$ Your solution fails for all $n < 10$ because you're double-counting. For instance, for $n = 9$ you're counting $0000000000$ twice: once where $x = 0$ on the left, and once where $x = 0$ on the right. $\endgroup$ Jul 10, 2013 at 8:41
  • 1
    $\begingroup$ Just for clarification -- a string containing a block of 7 consecutive zeroes should also count as having 6, 5, 4, ... 0 consecutive zeroes too, right? E.g. for $n=0$, you'd get the answer to be $10^{10}$ and for $n=1$ it'd be $10^{10}-9^{10}$ (all strings, apart from those having no zeroes at all); is that correct? $\endgroup$ Jul 10, 2013 at 8:52

2 Answers 2


In my experience, if it is difficult to calculate a probability, it is sometimes easier to calculate the inverse.

So how many 10 digit strings do not contain consecutive 0s?

We can ignore the first digit since one digit in of itself will have no impact on the probability.

From there, the probability that a single digit does not cause that string to contain consecutive 0s is inverse of the the probability that both the previous and the current digits are 0.

So if we were solving for 2 digit strings, the probability would simply be the inverse of the probability of having 0 digit followed by another 0 digit, or $1 - (\frac{1}{10\times10})$.

If we were to then apply this to a 3 digit string, the probability would be compounded with the inverse of the probability of the last digits having 0. This simply means to find the probability of not finding 0s in the first two digits and not finding 0s in the second two digits. This also covers the case of both finding digits in the first 2 digits as well as finding digits in the last 2 digits.

The probability of the first two digits not both having 0 is $1 - (\frac{1}{10\times10})$, and the probability of the last two digits not both having 0 is $1 - (\frac{1}{10\times10})$. Compounded, you would get $$1 - \frac{1}{\frac{1}{1 - (\frac{1}{10\times10})}\times\frac{1}{1 - (\frac{1}{10\times10})}}$$ Simplying a bit, we get: $$1 - (1 -\frac{1}{10\times10})^{2}$$

Why the 2? Because we have 3 digits and 2 pairs of digits to consider. Generalizing, we would have: $$1 - (1 - \frac{1}{10\times10})^{n-1}$$ Where $n$ is the number of digits. Take this probability and multiply times $10^n$ or in this case $10^{10}$ (total number of possible combinations) and you get the number of digits containing consecutive zeros.

It would seem that you're making the mistake of assuming the pattern is linear. When you're finding all configurations of non-0 digits in the case in which m is 1, there should be just as many configurations of 0 digits in the case in which m is 9. So: $$xxxxxxxxx0,0xxxxxxxxx$$

If your linear calculation were accurate, then there should be 10000000000 ways to place that singular 0 digit! Hope that helps!


As detailed in this related post, the
Number of decimal strings, of length $n$, having at most $r$ consecutive zeros
is given by: $$ \bbox[lightyellow] { \eqalign{ & T(r,n)\quad \left| {\;0 \le r \le n} \right.\quad = \cr & = \sum\limits_{\left( {0\, \le } \right)\,\,s\,\,\left( { \le \,n} \right)} {9^{\,n - s} \sum\limits_{\left( {0\, \le } \right)\,\,k\,\,\left( { \le \,\min \left( {{s \over {r + 1}}\,,\,n - s + 1} \right)} \right)} {\left( { - 1} \right)^k \left( \matrix{ n - s + 1 \cr k \cr} \right)\left( \matrix{ n - k\left( {r + 1} \right) \cr s - k\left( {r + 1} \right) \cr} \right)} } \cr} }$$ which in your case for a length $n=10$, taking $T(r,10)-T(r-1,10)$, gives (for $r=0\cdots 10$) $$3486784401,\; 5710687839,\; 729612360,\; 66515661,\; 5849739,\; 504000,\; 42300,\; 3420,\; 261,\; 18,\; 1$$ and you can check that it correctly gives a total of $10^{10}$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.