Maximum Number of Vowels in a Substring

MediumStringSliding WindowMath

Description

Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.

Examples

Input:s = "abciiidef", k = 3
Output:3
Explanation:

Sliding window of size 3: substring 'iii' at positions 3-5 contains all vowels. Maximum count: 3.

Input:s = "leetcode", k = 3
Output:2
Explanation:

The substring "eec" contains 2 vowels (e, e), which is the maximum possible for any substring of length 3.

Input:s = "programming", k = 4
Output:2
Explanation:

Multiple substrings of length 4 contain exactly 1 vowel each (like "prog", "rogr", "ogra", "gram", "ramm", "ammi", "mmin", "ming"), and this is the maximum possible.

Constraints

  • 1 ≤ s.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!