Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
How many binary strings of length 6 contain neither two consecutive 0s nor three consecutive 1s?
- A. 9
- B. 11
- C. 6
- D. 21
Correct answer: A. 9
Enumerate strings with a state DP: the state is the last one or two bits and the current run length. Dropping the '111' rule, or dropping the '00' rule, gives a different count.
More Coding Interview Problems questions
- How many subsets (including the empty subset) of [3, 5, 9, 11, 14, 2] have a sum divisible by 7?
- Closed intervals [1,4], [2,6], [4,7], [5,9], [8,10] are given. What is the largest number of intervals that share a single integer point?
- Array [2, 8, 9, 18, 4, 16, 6, 3]. How many index pairs i < j have a[i] a[j] equal to a perfect square?
- Array [1, 2, 4, 3, 0, 5, 6]. What is the length of the longest contiguous subarray in which the XOR of the elements equals their sum?
- Ropes of lengths 4, 3, 2 and 6 are joined two at a time; joining ropes of lengths x and y costs x + y and creates one rope of length x +…
- Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?