Count letter frequencies in a string and return the sum of the most frequent vowel and the most frequent consonant.
Problem
You are given a string s consisting of lowercase English letters.
A vowel is one of a, e, i, o, u. A consonant is any other lowercase letter.
Your task is to:
- Count how many times each vowel appears in
s. - Count how many times each consonant appears in
s. - Find the highest frequency among all vowels and the highest frequency among all consonants.
- Return the sum of these two values.
If the string contains no vowels, treat the vowel frequency as 0. If it contains no consonants, treat the consonant frequency as 0.
Notes
- The answer is based on character frequencies, not distinct letters.
- Only lowercase letters are considered in this formulation.
Input Format
- A single string
s. scontains lowercase English letters.
Output Format
- Return one integer: the sum of the maximum vowel frequency and the maximum consonant frequency.
Constraints
s[i]is a lowercase English letter
Example 1
Input
s = "successes"
Output
5
Explanation
Vowel counts: u = 1, e = 2 so the most frequent vowel appears 2 times. Consonant counts include s = 4, c = 2; the most frequent consonant appears 4 times. The sum is 2 + 4 = 6.
Correction: for successes, the answer is 6.
Example 2
Input
s = "leetcode"
Output
4
Explanation
Vowel counts: e = 3, o = 1, a/i/u = 0, so max vowel frequency is 3. Consonant counts: l = 1, t = 1, c = 1, d = 1, so max consonant frequency is 1. Total = 4.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.