Data Structures & AlgorithmsHardTCS NQT · Infosys
Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?
- A. 34
- B. 13
- C. 21
- D. 32
Correct answer: B. 13
With both ends 1, the five middle bits only need no '00', which is F(7) = 13 strings. All good strings of length 7 number 34, those that merely start with 1 number 21, and 2^5 = 32 ignores the no-00 rule.
More Coding Interview Problems questions
- Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then…
- Problem: How many subarrays of [2, 4, 6, 1, 3, 5] have all elements even or all elements odd?
- Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?
- Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell…
- Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.
- Problem: The array [4, 9, 2, 7, 5, 6] is processed by insertion sort (standard insertion into the sorted prefix, shifting larger elements…