Make Letter Counts Distinct
Delete the fewest characters from s so that no two different letters are left with the same number of occurrences. A letter deleted entirely (count 0) is simply gone and clashes with nothing. Return the number of deletions. The empty string needs 0 deletions.
Example 1
s "aab"
returns 0
a appears twice and b once, already different counts.
Example 2
s "aaabbbcc"
returns 2
The counts are 3 (a), 3 (b) and 2 (c). Delete one b to make its count 2, which then clashes with c, so delete one c as well: 2 deletions, leaving counts 3, 2, 1.
Constraints
0 <= len(s) <= 60shas lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.