Maximum Vowels in a Substring (LeetCode 1456) | Full solution with animations | Sliding Window

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

Chapters:
00:00 - Intro
00:40 - Problem Statement
02:49 - Brute Force Solution
04:35 - Efficient Solution
09:24 - Dry-run of Code
12:09 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

your explanation is on next level 🔥🔥...
and your final thoughts is really helpful
thank u so much..

jatin_
Автор

Please make a playlist, so i can solve all these type of question at first and then watch your video if i got stuck

ankitguptadotcom
Автор

Thanks, bro, but I didn't understand why you started the second loop with 'i=k' (we only need to increment 'i' once). Let's say, for example, k=3; at that point, we don't check the values 0 and 1. Also, why should the condition be 'i<k' instead of 'i<s.length()' to iterate the loop k times?

mohammadsalim
Автор

May be Elements of the array are contiguous .but string is also a char array, so, i think elements in the string also contiguous

saikiran
Автор

Initially I used string to store aeiou then use string contains method to check if vowels are there or not, so iam guessing this check takes longer time than looking in Hashset

AngelOfDeath
Автор

cpp














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

SubhajitDas-mtsn
Автор

i didn't realize this was a 4k video, that's why i wonder why the video buffer in a seconds 😅

nabil
Автор

You are doing soo great Please never stop 🤌🏻✨✨

danishshaikh
welcome to shbcf.ru