From e648ecc896f5ac7db93b046699adf1832e74405f Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 12 Sep 2025 22:24:30 -0600 Subject: 3541. find most frequent vowel and consonant --- find_frequent_vowel_consonant.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 find_frequent_vowel_consonant.py (limited to 'find_frequent_vowel_consonant.py') diff --git a/find_frequent_vowel_consonant.py b/find_frequent_vowel_consonant.py new file mode 100644 index 0000000..dbbba95 --- /dev/null +++ b/find_frequent_vowel_consonant.py @@ -0,0 +1,34 @@ +# 3541. Find Most Frequent Vowel and Consonant + +""" +you are given a string 's' consisting of lowercase english letters 'a' to +'z'. your task is to find the vowel with the maximum frequency, and find the +consonant with the maximum frequency. return the sum of the two frequencies. +note if multiple vowels or consonants have the same maximum frequency, you +may choose any one of them. if there are no vowels or consonants in the +string, consider their frequency as 0. +""" + + +class Solution(object): + def maxFreqSum(self, s): + """ + :type s: str + :rtype: int + """ + freq = [0] * 26 + max_v, max_c = 0, 0 + for c in s: + i = ord(c) - ord("a") + freq[i] += 1 + if c in "aeiou": + max_v = max(max_v, freq[i]) + else: + max_c = max(max_c, freq[i]) + return max_v + max_c + + +if __name__ == "__main__": + obj = Solution() + print(obj.maxFreqSum(s="successes")) + print(obj.maxFreqSum(s="aeiaeia")) -- cgit v1.2.3