2025-08-24 14:46:18 +0000 UTC

Find Most Frequent Vowel and Consonant

Code

class Solution:
    def maxFreqSum(self, s: str) -> int:
        freqs, n = [0] * 26, len(s)
        for i in range(n):
            freqs[ord(s[i]) - 97] += 1
        max_vow, max_con = 0, 0
        vow = tuple(ord(ch) - 97 for ch in ("a", "e", "i", "o", "u"))
        for i in range(26):
            if i in vow:
                max_vow = max(max_vow, freqs[i])
            else:
                max_con = max(max_con, freqs[i])
        return max_vow + max_con