Remove Letter To Equalize Frequency - Problem
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 from word so that the frequency of every letter present in word is equal.
Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.
Note:
- The frequency of a letter
xis the number of times it occurs in the string. - You must remove exactly one letter and cannot choose to do nothing.
Input & Output
Example 1 — Two Close Frequencies
$
Input:
word = "abcc"
›
Output:
true
💡 Note:
Remove one 'c' to get "abc": a:1, b:1, c:1 - all frequencies equal
Example 2 — Cannot Equalize
$
Input:
word = "aab"
›
Output:
true
💡 Note:
Remove one 'a' to get "ab": a:1, b:1 - all frequencies equal
Example 3 — Single Character Type
$
Input:
word = "aaa"
›
Output:
true
💡 Note:
Remove one 'a' to get "aa": only character 'a' with frequency 2
Constraints
- 1 ≤ word.length ≤ 105
- word consists of lowercase English letters
- You must remove exactly one character
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code