Find the Longest Substring Containing Vowels in Even Counts | Leetcode 1371 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 19th Video of our Playlist "Bit Manipulation : Popular Interview Problems" by codestorywithMIK
We will also see why sliding window is not a feasible solution for this.
In this video we will try to solve an easy problem : Find the Longest Substring Containing Vowels in Even Counts | Multiple Ways | Leetcode 1371 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Find the Longest Substring Containing Vowels in Even Counts | Multiple Ways | Leetcode 1371 | codestorywithMIK
Company Tags : Yogiyo (Food delivering app)
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/find-th...
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach 1 (Using a Map to Store States)
Time Complexity (T.C.): O(n)
Space Complexity (S.C.): O(1)
Description: This approach uses an unordered map to track the state of vowels in the string (whether their counts are even or odd). It maintains a vector that tracks the count of the five vowels (a, e, i, o, u), and for each character, updates the state of the vowels. If a state (string of binary digits representing vowel parity) is found in the map, it calculates the substring length. Otherwise, it stores the first occurrence of that state in the map. The solution ensures that all vowel counts are even to find the longest valid substring.
Approach 2 (Using XOR for State and Map)
Time Complexity (T.C.): O(n)
Space Complexity (S.C.): O(1)
Description: This approach is similar to the first but uses XOR to toggle the vowel counts between even and odd. The idea is to flip the state of a vowel (0 to 1 and vice versa) using XOR for each occurrence. Like the first approach, a map is used to store the first occurrence of each state. XOR makes the approach more efficient in handling bitwise operations, and a string representing the state is used to track the current state of vowels in binary form.
Approach 3 (Using Mask and XOR)
Time Complexity (T.C.): O(n)
Space Complexity (S.C.): O(1)
Description: This approach uses bit manipulation, representing the state of the five vowels using a 5-bit mask. Each vowel corresponds to a specific bit position, and XOR is used to toggle the bits in the mask when a vowel is encountered. The mask is stored in an unordered map with its first occurrence. If the current mask was seen before, the length of the substring is calculated. This approach reduces space complexity since it only needs to track at most 25 states, making it highly efficient for this problem.
All three approaches maintain O(n) time complexity and optimize the space complexity using bit manipulation, with Approach 3 being the most space-efficient due to the use of a bitmask.
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik
Other Videos By codestorywithMIK
Other Statistics
Counter-Strike: Source Statistics For codestorywithMIK
At this time, codestorywithMIK has 34,577 views for Counter-Strike: Source spread across 5 videos. Less than an hour worth of Counter-Strike: Source videos were uploaded to his channel, making up less than 0.10% of the total overall content on codestorywithMIK's YouTube channel.