Find Most Frequent Vowel and Consonant - Problem

You are given a string s consisting of lowercase English letters ('a' to 'z'). Your task is to:

  • Find the vowel (one of 'a', 'e', 'i', 'o', or 'u') with the maximum frequency.
  • Find the consonant (all other letters excluding vowels) 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 no consonants in the string, consider their frequency as 0.

The frequency of a letter x is the number of times it occurs in the string.

Input & Output

Example 1 — Mixed Vowels and Consonants
$ Input: s = "hello"
Output: 3
💡 Note: Vowel frequencies: e=1, o=1. Consonant frequencies: h=1, l=2. Max vowel freq = 1, max consonant freq = 2. Result: 1 + 2 = 3
Example 2 — Repeated Vowel
$ Input: s = "aabbcc"
Output: 4
💡 Note: Vowel frequencies: a=2. Consonant frequencies: b=2, c=2. Max vowel freq = 2, max consonant freq = 2. Result: 2 + 2 = 4
Example 3 — Only Vowels
$ Input: s = "aeiou"
Output: 1
💡 Note: All characters are vowels with frequency 1 each. No consonants. Max vowel freq = 1, max consonant freq = 0. Result: 1 + 0 = 1

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consists only of lowercase English letters

Visualization

Tap to expand
Find Most Frequent Vowel and ConsonantInput: "hello"helloVowels:e: 1o: 1Max: 1Consonants:h: 1l: 2Max: 2Result: 1 + 2 = 3Sum of maximum frequencies
Understanding the Visualization
1
Input String
Given string with lowercase letters to analyze
2
Count & Categorize
Count frequencies and separate vowels from consonants
3
Find Maximums
Get maximum frequency from each category and sum them
Key Takeaway
🎯 Key Insight: Categorize letters while counting to track separate maximums efficiently
Asked in
Google 35 Amazon 28 Microsoft 22 Facebook 18
23.4K Views
Medium Frequency
~15 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen