Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the minimum number of characters that must be deleted from aaaabbbbcccdd so that no two letters occur the same number of times?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Sort the frequencies descending and lower each one until it is unused and positive. Keeping frequencies equal to already used values costs deletions the greedy correctly counts.
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 values appear among the sums of all non-empty contiguous subarrays of [1, 2, 3]?
- How many subarrays of [2, 5, 1, 5, 3] have a maximum value that occurs exactly once inside the subarray?
- How many elements of the array [3, 1, 4, 1, 5, 9, 2, 6] have no strictly greater element anywhere to their right?
- How many index pairs i < j in the array [6, 9, 2, 7, 4, 1] satisfy a[i] + i = a[j] + j (0-based indices)?
- For the array [3, -1, -5, 4, 2, -6, 7], how many non-empty contiguous subarrays have a sum divisible by 4? Remainders are taken as the…
- How many contiguous subarrays of [5, 2, 7, 1, 4, 6] have bitwise XOR exactly 3? Use prefix XOR values p[0]=0, p[i]=B[0]^…^B[i−1].