Maximum Number of Vowels in a Substring of Given Length - Problem
Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
Input & Output
Example 1 — Basic Case
$
Input:
s = "abciio", k = 2
›
Output:
2
💡 Note:
The substring "ii" contains 2 vowels, and "io" contains 2 vowels. All substrings of length 2: "ab"=1, "bc"=0, "ci"=1, "ii"=2, "io"=2. Maximum is 2.
Example 2 — All Consonants
$
Input:
s = "rhythms", k = 4
›
Output:
0
💡 Note:
No vowels in the string, so any substring of length 4 contains 0 vowels
Example 3 — All Vowels
$
Input:
s = "aeiou", k = 2
›
Output:
2
💡 Note:
Any substring of length 2 contains exactly 2 vowels: "ae", "ei", "io", "ou" all have 2 vowels
Constraints
- 1 ≤ s.length ≤ 105
- s consists of lowercase English letters
- 1 ≤ k ≤ s.length
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code