java.lang.Object
g1601_1700.s1647_minimum_deletions_to_make_character_frequencies_unique.Solution

public class Solution extends Object
1647 - Minimum Deletions to Make Character Frequencies Unique.<p>Medium</p> <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>'a'</code> is <code>2</code>, while the <strong>frequency</strong> of <code>'b'</code> is <code>1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;aab&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> <code>s</code> is already good.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aaabbbcc&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> You can delete two &rsquo;b&rsquo;s resulting in the good string &ldquo;aaabcc&rdquo;. Another way it to delete one &lsquo;b&rsquo; and one &lsquo;c&rsquo; resulting in the good string &ldquo;aaabbc&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;ceabaacb&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> You can delete both &rsquo;c&rsquo;s resulting in the good string &ldquo;eabaab&rdquo;. Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> contains only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minDeletions

      public int minDeletions(String s)