Problem Statement
leetcode problem link
Brute Force [Accepted]
class Solution:
def maxFreqSum(self, s: str) -> int:
vowels = {'a','e','i','o','u'}
freq = Counter(s)
max_vowels = max_consonants = 0
for c, v in freq.items():
if c in vowels:
max_vowels = max(max_vowels, v)
else:
max_consonants = max(max_consonants, v)
return max_vowels + max_consonants
Editorial
from collections import Counter
class Solution:
def maxFreqSum(self, s: str) -> int:
mp = Counter(s)
vowel = max((mp[ch] for ch in mp if ch in "aeiou"), default=0)
consonant = max((mp[ch] for ch in mp if ch not in "aeiou"), default=0)
return vowel + consonant