Skip to main content
Back to problems
Leetcode
Medium
Strings
Hash Maps
Arrays
Find Most Frequent Vowel And Consonant

Count letter frequencies in a string and return the sum of the most frequent vowel and the most frequent consonant.

Acceptance 0%
Problem Statement

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:

  1. Count how many times each vowel appears in s.
  2. Count how many times each consonant appears in s.
  3. Find the highest frequency among all vowels and the highest frequency among all consonants.
  4. 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.
  • s contains lowercase English letters.

Output Format

  • Return one integer: the sum of the maximum vowel frequency and the maximum consonant frequency.

Constraints

  • 1s1051 \le |s| \le 10^5
  • s[i] is a lowercase English letter
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.