Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional

Count the binary strings of length 10 that contain no two adjacent 1s and also contain a run of at least three consecutive 0s. Brute-force all 1024 strings.

Count the binary strings of length 10 that contain no two adjacent 1s and also contain a run of at least three consecutive 0s. Brute-force all 1024 strings.
import itertools
c=0
for t in itertools.product('01',repeat=10):
    s=''.join(t)
    if '11' not in s and '000' in s: c+=1
print(c)
What is printed?
  1. A. 75
  2. B. 144
  3. C. 142
  4. D. 116

Correct answer: D. 116

Filter strings by the no-11 rule and require a 000 block, then count. Dropping the run requirement counts all no-11 strings, requiring only a pair of zeros admits more strings, and demanding four zeros excludes valid ones.

More Coding Interview Problems questions

Exams that ask this topic