Minimum Deletions to Make Character Frequencies Unique

A string s is good when no two different characters in s have the same frequency (the number of times the character appears). Given s, return the minimum number of characters you must delete to make s good. A character whose frequency drops to 0 no longer counts.

30:00

Minimum Deletions to Make Character Frequencies Unique
medium
Free written solution
Topics
Companies

A string s is good when no two different characters in s have the same frequency (the number of times the character appears). Given s, return the minimum number of characters you must delete to make s good. A character whose frequency drops to 0 no longer counts.

Example 1:
Input: {"s":"aab"}
Output: 0
Constraints:
  • 1≤s.length≤1051 \leq s.\text{length} \leq 10^5

  • s contains only lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"aab"}

Count each letter of "aab". Two letters may not share a count, so some bars have to be cut down.

letter counts

a

2

b

1

counts already taken (each used once)

none yet

deletions so far

0

Variables
VariableValue
allowed3
deletions0
DepthFunction Call
Stack empty
0/7