Remove Letter To Equalize Frequency - Problem

You're given a string of lowercase English letters and need to determine if you can make all remaining characters appear with equal frequency by removing exactly one character.

Think of it like balancing a scale: after removing one letter, every unique character that remains must appear the same number of times. For example, if you have the string "aabbcc", all letters appear twice, so removing any one letter would break this balance. But if you had "aaabbc", removing one 'a' would leave you with "aabbc" where 'a' appears 2 times, 'b' appears 2 times, and 'c' appears 1 time - not balanced.

Key Rules:

  • You must remove exactly one character (no more, no less)
  • After removal, all remaining unique characters must have identical frequencies
  • Return true if this is possible, false otherwise

Input & Output

example_1.py — Basic Case
$ Input: word = "abcc"
Output: true
💡 Note: We can remove one 'c' to get "abc" where each character appears exactly once (frequency = 1)
example_2.py — Equal Frequencies
$ Input: word = "aabbcc"
Output: false
💡 Note: All characters already have equal frequency (2). Removing any one character breaks this balance and makes frequencies unequal
example_3.py — Single Character
$ Input: word = "a"
Output: true
💡 Note: After removing the only character 'a', we have an empty string which vacuously satisfies the equal frequency condition

Constraints

  • 1 ≤ word.length ≤ 105
  • word consists of lowercase English letters only
  • You must remove exactly one character

Visualization

Tap to expand
Library Book BalanceShelf A (3 books)Shelf B (2 books)Shelf C (1 book)Can we remove 1 book to balance all shelves?✓ Remove 1 book from Shelf C → Empty shelf (remove character)Result: A:3, B:2 (still unequal)✓ Remove 1 book from Shelf A → A:2, B:2, C:1 (still unequal)✓ Remove 1 book from Shelf B → A:3, B:1, C:1 (still unequal)Pattern Analysis SolutionInstead of trying every removal, analyze frequency patterns mathematically!
Understanding the Visualization
1
Count Books
Count how many books are on each shelf (character frequencies)
2
Analyze Pattern
Look for patterns where removing one book creates balance
3
Valid Patterns
Check specific cases: all shelves have 1 book, or one shelf has 1 extra book, etc.
Key Takeaway
🎯 Key Insight: Only specific frequency distributions allow equal frequencies after one removal - analyze the pattern instead of trying every possibility!
Asked in
Meta 15 Google 12 Amazon 8 Microsoft 6
26.8K Views
Medium Frequency
~25 min Avg. Time
890 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