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

Опубликовано: 27 Май 2020
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн String - 14: Smallest Sub-string which contains all the characters of given Pattern | Java Code длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Coding Simplified 27 Май 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 13,149 раз и оно понравилось 201 зрителям. Приятного просмотра!