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…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SalahElhossiny

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 chose to do nothing.


class Solution:
    def equalFrequency(self, word: str) -> bool:
        n = len(word)
        for i in range(n):
            if len(set(Counter(word[0:i] + word[i+1:]).values())) == 1:
                return True
        return False



This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SalahElhossiny


Print Share Comment Cite Upload Translate Updates
APA

SalahElhossiny | Sciencx (2022-10-26T10:14:53+00:00) Remove Letter To Equalize Frequency. Retrieved from https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/

MLA
" » Remove Letter To Equalize Frequency." SalahElhossiny | Sciencx - Wednesday October 26, 2022, https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/
HARVARD
SalahElhossiny | Sciencx Wednesday October 26, 2022 » Remove Letter To Equalize Frequency., viewed ,<https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/>
VANCOUVER
SalahElhossiny | Sciencx - » Remove Letter To Equalize Frequency. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/
CHICAGO
" » Remove Letter To Equalize Frequency." SalahElhossiny | Sciencx - Accessed . https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/
IEEE
" » Remove Letter To Equalize Frequency." SalahElhossiny | Sciencx [Online]. Available: https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/. [Accessed: ]
rf:citation
» Remove Letter To Equalize Frequency | SalahElhossiny | Sciencx | https://www.scien.cx/2022/10/26/remove-letter-to-equalize-frequency/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.