Data Structures & AlgorithmsVery hardGATE CS · CAT · MBA placement
How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- A. 30
- B. 26
- C. 27
- D. 34
Correct answer: C. 27
Count no-adjacent-1 strings with a DP that tracks the parity of zeros as a second state. Ignoring the parity gives the Fibonacci count 55 for n = 8, which is larger than the parity-restricted 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
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?
- What is the maximum sum of a contiguous subarray of [4, -1, 2, 2, 5, -3, 4, 1] that contains at most 2 distinct values?
- What is the minimum number of characters you must delete from "abbabaab" (keeping the order of the rest) so that the result contains NO…
- How many ordered pairs (i, j) with i ≠ j exist in [2, 4, 3, 8, 6, 9] such that a[j] is divisible by a[i]?
- From the stick lengths [4, 2, 7, 5, 3, 6, 9], choose three different sticks that can form a non-degenerate triangle (the sum of any two…
- How many integers x with 1 ≤ x < 300 have the same decimal digit sum as x + 1?