Skip to content

Commit 3643f28

Browse files
authored
Create 1456-maximum-number-of-vowels-in-a-substring-of-given-length.py
1 parent 7d7531e commit 3643f28

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def maxVowels(self, s: str, k: int) -> int:
3+
vowels = set('aeiou')
4+
5+
# Count vowels in the first window
6+
curr_count = sum(1 for char in s[:k] if char in vowels)
7+
max_count = curr_count
8+
9+
# Slide the window
10+
for i in range(k, len(s)):
11+
if s[i] in vowels:
12+
curr_count += 1
13+
if s[i - k] in vowels:
14+
curr_count -= 1
15+
16+
max_count = max(max_count, curr_count)
17+
18+
return max_count
19+

0 commit comments

Comments
 (0)