An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
October 26, 2022 10:14 am GMT
Original Link: https://dev.to/salahelhossiny/remove-letter-to-equalize-frequency-1nh8
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 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
Original Link: https://dev.to/salahelhossiny/remove-letter-to-equalize-frequency-1nh8
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To