Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

How many binary strings of length 10 contain no two adjacent 1s?

  1. A. 89
  2. B. 144
  3. C. 233
  4. D. 143

Correct answer: B. 144

Let f(n) be the count. A string either ends in 0, or ends in 01 after a valid prefix, so f(n) = f(n-1) + f(n-2) with f(1) = 2 and f(2) = 3. The sequence gives 144 at length 10; shifting the index by one gives 89 or 233.

More Coding Interview Problems questions

Exams that ask this topic