Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
How many binary strings of length 10 contain no two adjacent 1s?
- A. 89
- B. 144
- C. 233
- 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
- In how many ways can a 3 x 4 grid be covered completely by non-overlapping 1 x 2 dominoes (each domino covers two adjacent cells, in…
- The universe {0, ..., 5} must be covered by a union of chosen sets from {0,1,2}, {2,3}, {3,4,5}, {0,4}, {1,5}. What is the minimum number…
- How many subsets (including the empty subset) of {1, 2, ..., 10} have a sum divisible by 3?
- From the values [3, 34, 4, 12, 5, 2, 19, 8], choose any subset (the empty subset allowed). What is the smallest possible value of |(sum of…
- Arrays A = [1, 2], B = [-2, -1], C = [-1, 2] and D = [0, 2] each have two entries. How many index quadruples (i, j, k, l) satisfy A[i] +…
- How many subsets of {1, 2, ..., 10} have a sum of exactly 10? The single-element subset {10} counts as one of them.