Data Structures & AlgorithmsHardCodeforces Div2 C · combinatorics
Problem: How many binary strings of length 5 contain no two consecutive 1s?
- A. 8
- B. 21
- C. 13
- D. 12
Correct answer: C. 13
If f(n) counts valid strings of length n, then f(n) = f(n-1) + f(n-2) with f(1) = 2 and f(2) = 3, so f(5) = 13. Allowing any strings gives 32 and dropping the last-bit case gives the trap 8.
More Coding Interview Problems questions
- Problem: What is the maximum product of a non-empty contiguous subarray of [2, 3, -2, 4, -1]? Use the code below. python a = [2, 3, -2, 4…
- Problem: How many islands (4-connected groups of '1') are in the grid below? Run the DFS code. python g = ['11000', '11000', '00100'…
- Problem: How many subarrays of [1, -1, 2, -2, 3, -3] have sum zero? Run the prefix-count code. python from collections import Counter a =…
- Problem: A data stream needs the median of the last k elements. Which structure supports each slide in O(log k) time?
- Problem: Consider a connected undirected graph whose edge weights are all distinct. Which statement is true?
- Problem: What is the standard time complexity of bitmask DP for the travelling salesman problem on n cities?