Ctrl K

Distinct Letter Counts

Medium
You are given a string word of lowercase English letters. Delete as few characters as possible so that no two **different** letters left in the string occur the same number of times. Letters that have been removed completely are not compared. Return the minimum number of characters to delete.
Example 1
word="xxyyzzz" → 1

Both x and y appear twice. Delete one y: now x — 2, y — 1, z — 3, all different.

Example 2
word="abc" → 2

Every letter appears once. Only one of them can stay, so two are deleted. Letters that are gone entirely do not count.

Example 3
word="mmmmn" → 0
Constraints
  • 1 ≤ len(word) ≤ 10⁵
  • word consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNo Twin Letters Side by Side MediumNine-Button Layout MediumReassigning the Phone Keypad MediumPalindromes From Shared Letters MediumFill the Blanks With the Fewest Repeats Medium
loading Python…
Input
word="xxyyzzz"
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 26 tests on the server, hidden ones included.