Data Structures & AlgorithmsHard
How many binary strings of length 6 contain NO three equal bits in a row (no run of length 3 or more)?
- A. 26
- B. 62
- C. 20
- D. 60
Correct answer: A. 26
Count runs: each string is a sequence of runs of length 1 or 2 alternating in bit value, and a run-length DP gives the total. Brute force over the 64 strings confirms the value for length 6.
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
- What is the minimum number of elements you must DELETE from 7 4 9 2 5 8 so that the sum of the remaining elements is divisible by 6?…
- In "xaybzaxxbab", what is the length of the shortest contiguous substring that contains the letter 'a' followed later by the letter 'b'…
- How many contiguous subarrays of 4 2 7 1 5 3 6 of length at least 2 have their FIRST element equal to their minimum?
- How many contiguous subarrays of 1 2 4 3 5 2 have XOR equal to their SUM?
- What is the length of the shortest contiguous subarray of 1 4 2 7 3 5 6 1 whose sum is at least 14?
- How many contiguous subarrays of 2 3 4 5 6 7 8 contain EXACTLY two even values and have an ODD length?