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 x is 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
Remove Letter To Equalize Frequency: "abcc" → Equal FrequenciesabccInput: "abcc"abcAfter Removal: "abc"Original Frequencies:a:1, b:1, c:2New Frequencies:a:1, b:1, c:1Result: trueAll characters now have equal frequency (1)Pattern: Two frequencies differ by 1, remove the higher one
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.
Asked in
Google 15 Amazon 12 Facebook 8
32.4K Views
Medium Frequency
~25 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen