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

How many binary strings of length 8 contain no three consecutive 1s?

  1. A. 149
  2. B. 150
  3. C. 232
  4. D. 192

Correct answer: A. 149

Let t(n) count valid strings with a tribonacci recurrence: t(n) = t(n-1) + t(n-2) + t(n-3) for the ending zero or run of at most two ones. Subtracting strings that contain a block of three ones directly is a common error.

More Coding Interview Problems questions

Exams that ask this topic