Loading problem...
You are given a lowercase English string s and a positive integer k representing the window size. Your task is to find the maximum number of vowel characters that can appear in any contiguous segment (substring) of exactly k characters within the string.
A vowel in the English alphabet is defined as one of the following five characters: 'a', 'e', 'i', 'o', or 'u'.
You must scan through all possible contiguous windows of size k in the string and determine which window contains the highest concentration of vowels. Return this maximum count as an integer.
Key Observations:
s = "abciiidef"
k = 33We examine all substrings of length 3. The substring "iii" (at indices 3-5) contains 3 vowels, which is the maximum possible. Other substrings like "abc" contain 1 vowel ('a'), "bci" contains 1 vowel ('i'), "cii" contains 2 vowels, and so on.
s = "aeiou"
k = 22Every character in the string is a vowel. Any window of size 2 will contain exactly 2 vowels. For instance, "ae", "ei", "io", and "ou" all have 2 vowels. Therefore, the maximum is 2.
s = "leetcode"
k = 32Examining all windows of size 3: "lee" has 2 vowels ('e', 'e'), "eet" has 2 vowels ('e', 'e'), "etc" has 1 vowel ('e'), "tco" has 1 vowel ('o'), "cod" has 1 vowel ('o'), and "ode" has 2 vowels ('o', 'e'). The maximum vowel count among all windows is 2.
Constraints