Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created September 13, 2025 22:21
Show Gist options
  • Select an option

  • Save Ifihan/83789cc7fbd73ae6e5a12e09f781159b to your computer and use it in GitHub Desktop.

Select an option

Save Ifihan/83789cc7fbd73ae6e5a12e09f781159b to your computer and use it in GitHub Desktop.
Find Most Frequent Vowel and Consonant

Question

Approach

I count the frequencies of all characters in the string. Then I separate vowels (a, e, i, o, u) from consonants (all other lowercase letters). I track the maximum frequency among vowels and the maximum among consonants. If the string has no vowels or no consonants, I treat the missing side as 0. Finally, I return the sum of the two maxima.

Implementation

class Solution:
    def maxFreqSum(self, s: str) -> int:
        vowels = set("aeiou")
        freq = Counter(s)

        max_vowel = 0
        max_consonant = 0

        for ch, count in freq.items():
            if ch in vowels:
                max_vowel = max(max_vowel, count)
            else:
                max_consonant = max(max_consonant, count)

        return max_vowel + max_consonant

Complexities

  • Time: O(n)
  • Space: O(1)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment