Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1056 from NouraAlgohary/main
Browse files Browse the repository at this point in the history
add day 5
  • Loading branch information
7oSkaaa committed May 6, 2023
2 parents add0137 + a1293ee commit d1b8bd0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Author: Noura Algohary
// Use sliding window
class Solution {
public:
int maxVowels(string s, int k) {
int n = s.size(), vowelsCnt = 0;

for(int i = 0; i < k ; i++)
{
if(s[i] == 'a' || s[i] == 'e' ||s[i] == 'i' ||s[i] == 'o' ||s[i] == 'u')
vowelsCnt++;

}
int maxVowels = vowelsCnt;
for(int i = k; i < n; i++)
{
if(s[i] == 'a' || s[i] == 'e' ||s[i] == 'i' ||s[i] == 'o' ||s[i] == 'u')
++vowelsCnt;

if(s[i - k] == 'a' || s[i - k] == 'e' ||s[i - k] == 'i' ||s[i - k] == 'o' ||s[i - k] == 'u')
--vowelsCnt;

if(vowelsCnt > maxVowels)
maxVowels = vowelsCnt;
}
return maxVowels;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Author: Noura Algohary
# Use sliding window

class Solution:
def maxVowels(self, s: str, k: int) -> int:
vowelsCnt = 0

for i in range(k):
if s[i] in ['a', 'e', 'i', 'o', 'u']:
vowelsCnt += 1

maxVowels = vowelsCnt

for i in range(k, len(s)):
if s[i] in ['a', 'e', 'i', 'o', 'u']:
vowelsCnt += 1

if s[i - k] in ['a', 'e', 'i', 'o', 'u']:
vowelsCnt -= 1

if vowelsCnt > maxVowels:
maxVowels = vowelsCnt

return maxVowels

0 comments on commit d1b8bd0

Please sign in to comment.