Data Structures & AlgorithmsVery hard
For a binary string with no three equal consecutive bits, why is a run-length description convenient for counting?
- A. Runs can have any length, so no structure exists.
- B. Every string of length 6 has exactly three runs.
- C. The count equals 2 to the power of the number of runs.
- D. Each run has length 1 or 2, and the bit value alternates between consecutive runs, so the count follows a simple recurrence.
Correct answer: D. Each run has length 1 or 2, and the bit value alternates between consecutive runs, so the count follows a simple recurrence.
Restricting runs to length 1 or 2 with alternating values turns the count into a recurrence over the number of runs. This is a standard run-length DP.
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
- Why does the sliding-window approach fail to find the shortest subarray with sum divisible by m when values are NEGATIVE?
- Which property makes the ordered-pair count of A[i] > A[j] equal to the number of unequal unordered pairs?
- When an array's values are all distinct, what is the number of ordered pairs (i, j), i ≠ j, with A[i] > A[j]?
- Push and pop operations on an initially empty stack are: push, push, pop, push, push, push, pop, pop, push. What is the maximum height the…
- Customers arrive at times 0, 1, 2 and 5 and need service times 3, 2, 1 and 2 on a single server (first come, first served; a customer…
- For the same four customers (arrivals 0, 1, 2, 5; service times 3, 2, 1, 2) on a single first-come-first-served server, what is the…