Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: How many binary strings of length 8 have no two consecutive 1s and begin with the digit 0?

  1. A. 55
  2. B. 21
  3. C. 89
  4. D. 34

Correct answer: D. 34

A leading 0 leaves any valid string of length 7, and the count of length-n strings with no '11' is F(n + 2), so F(9) = 34. Ignoring the first-digit condition gives F(10) = 55, strings starting with 1 (forced '10' then length 6) give 21, and F(11) = 89 is length 9.

More Coding Interview Problems questions

Exams that ask this topic