Relative Content

Tag Archive for strings

Number of strings containing a specific substring

I’ve seen numerous questions (and answers) concerning the number of binary strings (e.g “10010” containing some binary substring (e.g “00”). I’d like to know if there is a way to generalize this:

Which way is more efficient for getting the space count?

I have just started reading Cracking the Coding Interview. One of the problems (specifically 1.4) after solving and then looking at the answer made me question the way it is done and decided to post it up here to see if I am missing something.