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:
s.s.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:
Input: s = "acab"
Output: 1
Explanation:
We can make s good by deleting one occurrence of character 'a'.
Example 2:
Input: s = "wddw"
Output: 0
Explanation:
We do not need to perform any operations since s is initially good.
Example 3:
Input: s = "aaabc"
Output: 2
Explanation:
We can make s good by applying these operations:
'a' to 'b''c' into sConstraints:
3 <= s.length <= 2 * 104s contains only lowercase English letters.occ where occ[x] is the number of occurrences of the x character of the alphabet. How do the described operations change occ?occ[x] by 1, decrease any occ[x] by 1, or decrease any occ[x] by 1 and simultaneously increase occ[x + 1] by 1 at the same time. To make s good, we need to make occ good. occ is good if and only if every occ[x] equals either 0 or some constant c.c, how can you calculate the minimum operations required to make occ good?occ[x] and occ[x + 1]. Instead, we can decrease occ[x] by 1 then increase occ[x + 2] by 1 to achieve the same effect.occ then decrease it, or vice versa.dp[i] is the minimum number of operations required to make occ[0..i] good. You will need to use the above observations to come up with the transitions."acab"
"wddw"
"aaabbc"