Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: How many binary strings of length 4 contain no two adjacent 1s?

  1. A. 8
  2. B. 13
  3. C. 5
  4. D. 16

Correct answer: A. 8

No-'11' strings follow a(n) = a(n−1) + a(n−2) with a(1) = 2, a(2) = 3, so a(4) = 8. Length 5 gives 13, length 3 gives 5, and 16 counts every string.

More Coding Interview Problems questions

Exams that ask this topic