Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many binary strings over the alphabet {a, b} of length 6 contain EXACTLY 2 occurrences of the adjacent pair "ab" (occurrences may not overlap in a way that matters here, since ab cannot overlap itself)?
- A. 35
- B. 25
- C. 21
- D. 6
Correct answer: C. 21
Track DP states by the last letter and the count so far: appending b after a adds one occurrence. Counting strings that merely contain 'ab' at least once is a different (larger) count.
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 binary strings of length 9 contain NO occurrence of the substring 010?
- In how many ways can the integer 10 be written as a sum of AT MOST 3 positive integers, where order does not matter (for example 10 = 7 +…
- From [1, 2, 3, 4, 6, 8, 12, 16, 18, 24, 36], choose the largest subset in which every pair of elements (the smaller divides the larger)…
- What is the largest XOR value obtainable as the XOR of a non-empty contiguous subarray of [8, 1, 2, 12, 7, 6]?
- What is the length of the longest arithmetic subsequence (equal consecutive differences, chosen by index) of [3, 6, 9, 12, 5, 10, 15, 20…
- Delete at most ONE element from [1, 3, 2, 5, 4, 6, 9, 7, 8] (or none). What is the length of the longest strictly increasing subsequence…