FunctionRacerProblemsRace

Make Letter Counts Distinct

MediumGreedyPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems