Remove Letter To Equalize Frequency

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.
Example 1
Inputword = "abcc"
Outputtrue
Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.
Example 2
Inputword = "aazz"
Outputfalse
We must delete a character, so either the frequency of "a" is 1 and the frequency of "z" is 2, or vice versa, making it impossible to make all present letters have equal frequency.

Constraints

  • 2 <= word.length <= 100
  • word consists of lowercase English letters only.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate