@laigary.com~/interview/coding/1456-maximum-number-….md$
$ cat ./coding/1456-maximum-number-of-vowels-in-a-substring-of-given-length.md
[Coding]·2024-03-09·1 min read

1456. Maximum Number of Vowels in a Substring of Given Length

1456. Maximum Number of Vowels in a Substring of Given Length

class Solution:
    def maxVowels(self, s: str, k: int) -> int:
        
        vowels = {"a", "e", "i", "o", "u"}

        count = 0
        for i in range(k):
            if s[i] in vowels:
                count += 1

        maxLength = count

        for i in range(k, len(s)):
            if s[i] in vowels:
                count += 1
            if s[i - k] in vowels:
                count -= 1
            maxLength = max(maxLength, count)

        return maxLength