LeetCode solutions

3872. Find Most Frequent Vowel and Consonant

My accepted Python solution to LeetCode problem 3872, Find Most Frequent Vowel and Consonant, running in 3ms.

  • Difficulty: Easy
  • Python
  • Runtime 3ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.3MB, accepted 2025-12-30.

python
class Solution:
    def maxFreqSum(self, s: str) -> int:
        from collections import Counter
        vowels = set('aeiou')
        cnt = Counter(s)
        max_vowel = max((cnt[c] for c in cnt if c in vowels), default=0)
        max_consonant = max((cnt[c] for c in cnt if c not in vowels), default=0)
        return max_vowel + max_consonant

Source