Maximum Number of Vowels in a Substring of Given Length | LeetCode 1456 | C++, Java, Python

preview_player
Показать описание

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

LeetCode 1456 | Maximum Number of Vowels in a Substring of Given Length
Facebook Coding Interview question,
google coding interview question,
leetcode,
Maximum Number of Vowels in a Substring of Given Length,
1456. Maximum Number of Vowels in a Substring of Given Length,
Maximum Number of Vowels in a Substring of Given Length c++,
Maximum Number of Vowels in a Substring of Given Length Java,
Maximum Number of Vowels in a Substring of Given Length Python,

#Facebook #CodingInterview #LeetCode #Google #Amazon
Рекомендации по теме
Комментарии
Автор

class Solution {
public:
int maxVowels(string s, int k) {
unordered_set<char> set = {'a', 'e', 'i', 'o', 'u'};
int max_vow = 0;
for (auto i = 0, cur_vow = 0; i < s.size(); ++i) {
cur_vow += set.count(s[i]);
if (i >= k)
cur_vow -= set.count(s[i-k]);
max_vow = max(max_vow, cur_vow);
}
return max_vow;
}
};

ForCodingInterview
Автор

You can also do Set set = Set.of('a', 'e', 'i', 'o', 'u');
instead of creating the list and then putting into the set

inspiredomkar
Автор

y we are setting the condition as vowels.end() there..why we cant simply set the condition as "if(vowels.find(s[i])" inside the for loop?

sriramv
Автор

Nice explanation.
I solved it using same strategy sliding window 😊

prabhatchanchal
Автор

paste your code in chat or give patreon links

krishnavar
Автор

In Hackerrank Python problem solving certificate this question is asked

consistentthoughts
Автор

C++ Runtime = 136ms
Java Runtime = 19ms
Python3 Runtime = 184ms
Why Runtime : Java << C++ < Python3 ?

afghaniiit
join shbcf.ru