Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many binary strings of length 6 contain no two consecutive 1s?
- A. 22
- B. 18
- C. 21
- D. 25
Correct answer: C. 21
These counts follow the Fibonacci recurrence: f(n) = f(n-1) + f(n-2), since the string either ends in 0 or ends in 10. Counting 2^6 - 6 ignores the constraint for longer runs.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many integers x with 1 <= x <= 500 are divisible by exactly one of 6 and 8?
- What is the value of the expression (1^2) + (2^2) + ... + (50^2) modulo 7?
- How many ordered pairs (a, b) with 1 <= a, b <= 30 satisfy a^2 + b^2 divisible by 7?
- A bank of 4 workers each processes one task per minute, and tasks arrive as a queue. In a single pass over the array of task lengths [3…
- How many subarrays of [3, 1, 4, 1, 5] have their minimum equal to their first element?
- What is the minimum possible value of the largest sum among the two groups when the array [7, 2, 5, 10, 8] is split into two contiguous…