Minimum Operations to Make Character Frequencies Equal

You are given a string s.

A string t is called good if all characters of t occur the same number of times.

You can perform the following operations any number of times:

  • Delete a character from s.
  • Insert a character in s.
  • Change a character in s to its next letter in the alphabet.

Note that you cannot change 'z' to 'a' using the third operation.

Return the minimum number of operations required to make s good.

Example 1
Inputs = "acab"
Output1
We can make s good by deleting one occurrence of character 'a'.
Example 2
Inputs = "wddw"
Output0
We do not need to perform any operations since s is initially good.

Constraints

  • 3 <= s.length <= 2 * 10^4
  • s contains only lowercase English letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate