Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the minimum number of characters that must be deleted from aabbaa so that no two adjacent characters of the remaining string are equal (characters may be deleted from any positions)?
- A. 4
- B. 5
- C. 7
- D. 3
Correct answer: D. 3
The longest subsequence with no equal neighbours is aba, of length 3, so 6 - 3 = 3 deletions are needed.
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 distinct strings can be obtained from aabb by removing exactly one character?
- What is the sum of the decimal digits of 100!?
- How many trailing zeros does 1000! have in base 10?
- How many integers x in [1, 300] satisfy x ≡ 1 (mod 4) and x ≡ 2 (mod 3)?
- What is Euler's totient phi(360), the number of integers in [1, 360] coprime to 360?
- How many unordered pairs of distinct integers {a, b} from 1 to 12 are coprime to each other?