Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code.

Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code.
import itertools
print(sum(1 for t in itertools.product('01', repeat=6) if '111' not in ''.join(t)))
What is printed?
  1. A. 40
  2. B. 42
  3. C. 48
  4. D. 44

Correct answer: D. 44

This count satisfies a tribonacci recurrence, giving 44 for length 6.

More Coding Interview Problems questions

Exams that ask this topic