Data Structures & AlgorithmsHard
What is the minimum number of characters to delete from "aabbbcaa" so that no two ADJACENT characters are equal?
- A. 5
- B. 4
- C. 3
- D. 2
Correct answer: B. 4
Each run of equal adjacent letters of length L needs L−1 deletions, and the total of these is the count of equal adjacent pairs. Counting distinct letters or unequal pairs measures a different quantity.
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 contiguous windows of length 3 in 5 3 4 6 2 7 1 8 are STRICTLY monotone (strictly increasing or strictly decreasing)?
- How many adjacent pairs (A[i], A[i+1]) in 4 7 2 9 1 8 5 6 have a sum of at least 10?
- In the 'maximum number of disjoint pairs with sum K' problem, why is a count-based greedy optimal?
- To find the longest subarray in which every value appears an even number of times, why can a parity bitmask over values be used with…
- Why is the minimum number of adjacent swaps to make a string palindromic NOT simply half the number of mismatched mirror pairs?
- When repeatedly deleting adjacent pairs of different letters, why does the final length have fixed parity?