<p>A string <code>s</code> is called <strong>good</strong> if there are no two different characters in <code>s</code> that have the same <strong>frequency</strong>.</p>

<p>Given a string <code>s</code>, return<em> the <strong>minimum</strong> number of characters you need to delete to make </em><code>s</code><em> <strong>good</strong>.</em></p>

<p>The <strong>frequency</strong> of a character in a string is the number of times it appears in the string. For example, in the string <code>&quot;aab&quot;</code>, the <strong>frequency</strong> of <code>&#39;a&#39;</code> is <code>2</code>, while the <strong>frequency</strong> of <code>&#39;b&#39;</code> is <code>1</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aab&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> <code>s</code> is already good.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aaabbbcc&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> You can delete two &#39;b&#39;s resulting in the good string &quot;aaabcc&quot;.
Another way it to delete one &#39;b&#39; and one &#39;c&#39; resulting in the good string &quot;aaabbc&quot;.</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;ceabaacb&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> You can delete both &#39;c&#39;s resulting in the good string &quot;eabaab&quot;.
Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code>&nbsp;contains only lowercase English letters.</li>
</ul>

class Solution:
    def minDeletions(self, s: str) -> int:
        # key insight is that we can 
        # Only delete values
        # once we have the initial freq
        # of all, we essentially want a 
        # bar graph where all are different
        # sizes. How to adjust them as such?
        # starting from the highest count
        # (we can only delete, and starting
        # from minimum count will required
        # backtracking) if there's more
        # then one in that bracket
        # move all but one of those occurences
        # down and adjust the total cost
        # keep going down each possible count
        # adjusting accordingly
        # in the best case, for each adjustment
        # (which is a single deletion depending on count)
        # the new freq of that char is a unique count
        # radix list is perfect for this problem
        # since it's already sorted and we really only care
        # how many are in that count (like counting sort)
        freq_mp = [0] * 26
        for c in s:
            freq_mp[ord(c)-ord('a')]+=1
        n = len(s)
        size_count_mp = [0] * (n+1)
        for freq in freq_mp:
            size_count_mp[freq] += 1
        # primary greedy algorithm
        min_cost = 0
        for i in range(n,0,-1):
            # move all but one into the next
            # retaining the values doesn't matter because we're not ADDING more
            if size_count_mp[i] > 1:
                deleted = size_count_mp[i]-1
                size_count_mp[i-1] += deleted
                min_cost += deleted
        return min_cost
202