Data Structures & AlgorithmsModerateCodeforces Div2 B · counting
Problem: How many binary strings of length 4 avoid the substring '11'? Run the code.
Problem: How many binary strings of length 4 avoid the substring '11'? Run the code.
print(sum(1 for t in range(16) if '11' not in format(t, '04b')))What is printed?
- A. 5
- B. 6
- C. 9
- D. 8
Correct answer: D. 8
The count follows Fibonacci: f(n) = f(n-1) + f(n-2) with f(1)=2, f(2)=3, f(3)=5, f(4)=8.
More Coding Interview Problems questions
- Problem: What is the minimum number of insertions and deletions needed to turn 'abc' into 'adc'? (Only insertions and deletions are…
- Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code. python import os…
- Problem: What does the following print? python print(' '.join('the sky is blue'.split()[::-1]))
- Problem: Which statement about Hall's theorem for a bipartite graph with sides L and R is correct?
- Problem: Which claim about the complexity of deciding 2-SAT (satisfiability of clauses with at most two literals) is correct?
- Problem: Which of the following problems is NP-complete (decision version)?