Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
How many binary strings of length 8 contain no three consecutive 1s?
- A. 149
- B. 150
- C. 232
- 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
- Array [5, 2, 8, 1, 4, 6, 3]. How many index pairs i < j have a[i] AND a[j] = 0 (no common set bit)?
- What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?
- Consider the eight primes 2, 3, 5, 7, 11, 13, 17, 19. How many subsets (including the empty subset, whose product is 1) have a product…
- How many 3-element subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum divisible by 6?
- Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time…
- Meetings are closed-open intervals [1,3), [2,5), [4,6), [5,7), [6,9), [8,10) and one room can hold one meeting at a time. A meeting may…