Skip to content
Decoder

Minimum Deletions to Make Character Frequencies Unique

Medium

Problem

A string is good if no two different letters in it appear the same number of times. Letters that appear zero times do not count. Return the minimum number of characters to delete from s to make it good.

Example 1

Input
s = "aab"
Output
0
Why
a: 2, b: 1

Example 2

Input
s = "aaabbbcc"
Output
2
Why
delete two b's: a 3, b 1, c 2

Example 3

Input
s = "ceabaacb"
Output
2

Constraints

  • 1 <= s.length <= 10^5
  • s contains only lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.