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?

  1. A. 4
  2. B. 2
  3. C. 5
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic