Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: How many binary strings of length 8 have no two consecutive 1s and begin with the digit 0?
- A. 55
- B. 21
- C. 89
- D. 34
Correct answer: D. 34
A leading 0 leaves any valid string of length 7, and the count of length-n strings with no '11' is F(n + 2), so F(9) = 34. Ignoring the first-digit condition gives F(10) = 55, strings starting with 1 (forced '10' then length 6) give 21, and F(11) = 89 is length 9.
More Coding Interview Problems questions
- Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?
- Problem: The longest bitonic subsequence (first strictly increasing, then strictly decreasing, either part may be empty) of [1, 11, 2, 10…
- Problem: Find the minimum path sum from the top to the bottom of the triangle [[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]], moving to an…
- Problem: The message "2261" is decoded by mapping 1→A, ..., 26→Z. Each decoding splits the digits into groups of one or two digits, each…
- Problem: 23 people stand in a circle numbered 1 to 23. Starting at person 1, every second person is eliminated (counting around the…
- Problem: Eight cards labelled 1 to 8 are in a row. A perfect out-shuffle splits the deck into two equal halves (1–4 and 5–8) and…