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:
false
💡 Note:
Remove 'a' → "ab" (a:1,b:1) or remove 'b' → "aa" (a:2) - cannot make equal after any single removal
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
Understanding the Visualization
1
Input Analysis
Count frequency of each character in the string
2
Pattern Recognition
Identify if frequency pattern allows valid removal
3
Result
Return true if equalization possible, false otherwise
Key Takeaway
🎯 Key Insight: Only specific frequency distribution patterns allow successful equalization after removing exactly one character.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code