Class Solution
-
- All Implemented Interfaces:
public final class Solution2423 - Remove Letter To Equalize Frequency\.
Easy
You are given a 0-indexed string
word, consisting of lowercase English letters. You need to select one index and remove the letter at that index fromwordso that the frequency of every letter present inwordis equal.Return
trueif it is possible to remove one letter so that the frequency of all letters inwordare equal, andfalseotherwise.Note:
The frequency of a letter
xis the number of times it occurs in the string.You must remove exactly one letter and cannot chose to do nothing.
Example 1:
Input: word = "abcc"
Output: true
Explanation: Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.
Example 2:
Input: word = "aazz"
Output: false
Explanation: We must delete a character, so either the frequency of "a" is 1 and the frequency of "z" is 2, or vice versa. It is impossible to make all present letters have equal frequency.
Constraints:
2 <= word.length <= 100wordconsists of lowercase English letters only.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanequalFrequency(String word)-
-
Method Detail
-
equalFrequency
final Boolean equalFrequency(String word)
-
-
-
-