Data Structures & AlgorithmsVery hardGATE CS
How many binary strings of length 12 contain neither 101 nor 010 as a substring?
- A. 460
- B. 466
- C. 470
- D. 1081
Correct answer: B. 466
Avoiding both patterns means every maximal run of equal bits other than the first and last has length at least 2. Enumeration gives 466 strings; avoiding only 101 would give 1081.
More Coding Interview Problems questions
- What are the last three digits of 7^2025?
- In a jump game, a[i] is the maximum jump length from index i (any length from 1 to a[i] is allowed). For a = [3, 1, 4, 1, 5, 9, 2, 6, 5…
- The sequence a1, ..., a14 is generated by a1 = 1 and a(i+1) = (5a(i) + 3) mod 17. How many pairs (i, j) with i < j satisfy a(i) > a(j)?
- In how many ways can 30 be written as a sum of distinct positive integers, each at most 10, if the order of the summands does not matter?
- An undirected weighted graph on vertices 0-5 has edges (u, v, w): (0,1,2), (0,2,2), (1,3,3), (2,3,3), (1,4,5), (2,4,5), (3,5,1), (4,5,1)…
- Problem: A delivery app logs the parcel weights of a day in an array. Return the indices of the two parcels whose weights add up exactly…