Data Structures & AlgorithmsVery hardGATE CS · CAT · MBA placement
How many binary strings of length 7 contain exactly 3 zeros and NO run of three equal consecutive digits (neither 000 nor 111 appears)?
- A. 18
- B. 22
- C. 3
- D. 35
Correct answer: A. 18
Build the string from runs: each run has length 1 or 2 and alternates between 0 and 1. Counting compositions of the zeros into runs of size at most 2 gives the answer. Ignoring the run-length cap gives C(7, 3) = 35 instead.
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
- Consider the array [1, 3, 2, 5, 4, 7, 6, 9]. You may change the value of AT MOST ONE element (to any integer). What is the length of the…
- What is the maximum value of x XOR y over all pairs of DIFFERENT positions of the list [7, 12, 5, 9, 14, 3]?
- Consider all non-empty contiguous subarrays of [2, 7, 3, 8, 6]. For each, take its sum modulo 10. What is the largest of these residues?
- A robot walks from the top-left corner of a 3 × 4 grid of cells to the bottom-right corner, moving only right or down. How many such paths…
- Two lists a = [4, 9, 1, 7] and b = [3, 8, 2, 10] are paired one-to-one (any bijection). What is the minimum possible value of the sum of…
- In the sequence [1, 3, 5, 2, 4, 6], how many strictly increasing subsequences have the maximum possible length (count by index positions)?