Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many binary strings of length 9 contain exactly 4 ones and no run of three or more consecutive 0s?
- A. 56
- B. 51
- C. 10
- D. 126
Correct answer: B. 51
Place the four ones and count the gaps of zeros between them (there are five gaps, each holding 0, 1 or 2 zeros), summing the ways for total zeros 5. Ignoring the run restriction gives the plain binomial C(9, 4) = 126.
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
- Closed integer intervals are [(1, 4), (2, 3), (5, 7), (4, 6), (8, 9), (7, 8)]. How many unordered pairs of intervals share at least one…
- The numbers [1, 6, 3, 8, 4] can be arranged in any order in a row. Maximise the sum of absolute differences between neighbouring numbers…
- Using only swaps of ADJACENT elements, what is the minimum number of swaps needed to turn [1, 2, 3, 2, 1, 3, 3] into a palindrome? (It is…
- How many contiguous subarrays of [3, 1, 3, 2, 5, 2, 5] contain exactly one occurrence of their maximum value?
- What is the length of the longest contiguous block of [1, 2, 3, 1, 2, 3, 4, 2, 3, 4] that appears at least twice in the array WITHOUT…
- What is the length of the longest subsequence of [1, 2, 4, 5, 7, 8, 10] that is strictly increasing and in which every two consecutive…