Data Structures & AlgorithmsHardTCS NQT · Infosys

Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?

  1. A. 34
  2. B. 13
  3. C. 21
  4. D. 32

Correct answer: B. 13

With both ends 1, the five middle bits only need no '00', which is F(7) = 13 strings. All good strings of length 7 number 34, those that merely start with 1 number 21, and 2^5 = 32 ignores the no-00 rule.

More Coding Interview Problems questions

Exams that ask this topic