Design Gurus Logo
Minimum Deletions to Make Character Frequencies Unique (medium)

Problem Statement

Given a string str, return the minimum number of characters you need to delete to make str good.

A good string doesn't contain two different characters with the same frequency.

Examples

Example 1:

  • Input: "aabbbb"
  • Expected Output: 0
  • Justification: In the given string, the frequency of a is 2, and the frequency of b is 4. Each character already has a unique frequency. So, no need to delete any character from the string

Example 2:

  • Input: "aaaabbbbcc"
  • Expected Output: 1
  • Justification: The character 'c' appears twice, and 'a' and 'b' appear four times each. To make all frequencies unique, we can delete one occurrence of either 'a' or 'b'. This leaves us with 'a', 'b', and 'c' having frequencies of 3, 4, and 2, respectively.

Example 3:

  • Input: "aabbcc"
  • Expected Output: 3
  • Justification: Here, each character's frequncey is 2. By deleting both a and 1 b, we can make frequency unique.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory