Minimum Window Substring: Utilizing Two Pointers & Tracking Character Mappings With A Hashtable
Back To Back SWE Back To Back SWE
237K subscribers
120,870 views
0

 Published On Feb 21, 2019

Code & Problem Statement @ https://backtobackswe.com/platform/co...

Free 5-Day Mini-Course: https://backtobackswe.com
Try Our Full Platform: https://backtobackswe.com/pricing
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions


Question: Given a string S and a string T, find the minimum window in S which will contain all the characters in T (matching or exceeding in frequency) in complexity O(n).

Anytime we have time reduced to linear time and we know that much must be done, that is indicative of using some sort of auxiliary structure to keep track of information for us so time can stay low in complexity.

Complexities

s = length of search string
t = length of "pattern" or "character" string

Time: O( s + t )
At worst we will touch each element twice, once by the left pointer and once by the right pointer.

Ex:
s = "aaaaat"
t = "t"

We will spend t time to build the character requirements hashtable.

Space: O( s + t )

At worst the window hashtable will have a mapping for every character in s.

At worst t will have all unique characters.

s = "abcdef"
t = "abcdef"

++++++++++++++++++++++++++++++++++++++++++++++++++

HackerRank:    / @hackerrankofficial  

Tuschar Roy:    / tusharroy2525  

GeeksForGeeks:    / @geeksforgeeksvideos  

Jarvis Johnson:    / vsympathyv  

Success In Tech:    / @successintech  

++++++++++++++++++++++++++++++++++++++++++++++++++

This question is 13.7 in the fantastic book Elements of Programming Interviews

show more

Share/Embed