Data Structures & AlgorithmsVery hardGATE CS

How many binary strings of length 12 contain neither 101 nor 010 as a substring?

  1. A. 460
  2. B. 466
  3. C. 470
  4. D. 1081

Correct answer: B. 466

Avoiding both patterns means every maximal run of equal bits other than the first and last has length at least 2. Enumeration gives 466 strings; avoiding only 101 would give 1081.

More Coding Interview Problems questions

Exams that ask this topic