String - 14: Smallest Sub-string which contains all the characters of given Pattern | Java Code

Publié le: 27 mai 2020
sur la chaîne: Coding Simplified
13,149
201

Source Code:https://thecodingsimplified.com/small...
Solution:
We create a map of frequency of characters present in pattern
Now we start from 1st index & if that character present in map, then we decrease the frequency by 1 & we check if the frequency is greater than 0, then we increase the matchedElement variable by 1
If matchedElement becomes equal to size of pattern then we've found our anagram & we store minimum length & starting point at this moment
Now we increase start & go until matchedElement is equal to pattern size. At every moment we update the starting point & min length if end - start + 1 is less than minLength
Now if any element is moving out of window, we check if it's part of map, then increase the frequency by 1 & if the frequency is 0 then decrease the matchedElement by 1
At last, we return substring starting from subStringStartIndex to subStringStartIndex + minLength

Time Complexity: O(n + m)
Space Complexity: O(m)

CHECK OUT CODING SIMPLIFIED
   / codingsimplified  

★☆★ VIEW THE BLOG POST: ★☆★
http://thecodingsimplified.com

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
https://www.youtube.com/codingsimplif...

★☆★ Send us mail at: ★☆★
Email: thecodingsimplified@gmail.com


Sur cette page du site, vous pouvez voir la vidéo en ligne String - 14: Smallest Sub-string which contains all the characters of given Pattern | Java Code durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Coding Simplified 27 mai 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 13,149 fois et il a aimé 201 téléspectateurs. Bon visionnage!