Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code.
Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code.
import itertools
print(sum(1 for t in itertools.product('01', repeat=6) if '111' not in ''.join(t)))What is printed?- A. 40
- B. 42
- C. 48
- D. 44
Correct answer: D. 44
This count satisfies a tribonacci recurrence, giving 44 for length 6.
More Coding Interview Problems questions
- Problem: How many derangements (permutations with no fixed point) of 1..6 exist? Run the code. python from itertools import permutations…
- Problem: How many permutations of 0..4 have exactly one inversion? Run the code. python from itertools import permutations print(sum(1 for…
- Problem: What is the smallest positive integer with exactly 10 positive divisors? Run the search. python n = 1 while sum(1 for d in…
- Problem: How many integers n in [1, 100] reach 1 under the Collatz map within 10 steps? Run the code. python def steps(n): c = 0 while n…
- Problem: How many ordered pairs (a, b) with 1 <= a, b <= 30 have a^2 + b^2 a perfect square? Run the code. python print(sum(1 for a in…
- Problem: How many distinct strings can be formed by rearranging the letters of 'aabbc'? Run the code. python from itertools import…