2
def minDeletions(self, s: str) -> int:3
# Get the frequency of each character sorted in reverse order4
frequencies = sorted(Counter(s).values(), reverse=True)7
next_unused_freq = len(s)8
for freq in frequencies:9
# It is impossible for the frequency to be higher10
next_unused_freq = min(next_unused_freq, freq)11
total_deletions += freq - next_unused_freq13
# We cannot have another character with this frequency,14
# so decrement next_unused_freq15
if next_unused_freq > 0:18
return total_deletions