Equal Character Frequencies After At Most One Removal
Problem statement
Given a lowercase string word, return whether you can make the string perfect by removing at most one character occurrence.
A string is perfect when every distinct character remaining in it occurs the same positive number of times. Removing no character is allowed.
Function
canEqualizeFrequency(word: String) → booleanExamples
Example 1
word = "abcc"return = trueRemove one c, leaving a, b, and c once each.
Example 2
word = "aazz"return = trueThe two present characters already have equal frequency, so use zero removals.
Example 3
word = "abbccc"return = falseThe frequencies 1, 2, and 3 cannot all become equal after only one decrement.
Constraints
1 <= word.length <= 100000.wordcontains only lowercase English letters.