Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
Example:
Input: S = "ADOBECODEBANC", T = "ABC"
Output: "BANC"
Note:
       If there is no such window in S that covers all characters in T, return the empty string "".
       If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
class Solution:
     def minWindow(self, s, t):
         """
         :type s: str
         :type t: str
         :rtype: str
         """
         # assume t doesn't have duplicated chars
         left=-1
         right = 0
         result = ""
 
         totalMatch = 0
         d = {}
         for c in t:
             d[c] = d.get(c, 0) + 1
 
         for right in range(len(s)):
             c = s[right]
             if c in d:
                 d[c]-=1
                 if d[c] >=0:
                     # good match
                     totalMatch +=1
 
                     if left == -1:
                         left = right
 
                     #find a sustring
                     if totalMatch == len(t):
                         if result == "" or len(result) > right - left:
                             result = s[left: right+1]
 
                         d[s[left]]+=1
                         totalMatch -=1
                         while left<right:
                             left +=1
 
                             if s[left] in d:
                                 if d[s[left]] <0:
                                     # skip over matched letter
                                     d[s[left]] +=1
                                 else:
                                     break
                 
                 elif c == s[left]:
                     d[c]+=1
                     while left < right:
                         left +=1
                         # skip over matched letter
                         if s[left] in d:
                             if d[s[left]] <0:
                                 d[s[left]] +=1
                             else:
                                 break
         return result
class Solution:
     def minWindow(self, s, t):
         """
         :type s: str
         :type t: str
         :rtype: str
         """
         # assume t doesn't have duplicated chars
         left=-1
         right = 0
         result = ""
 
         totalMatch = 0
         d = {}
         for c in t:
             d[c] = d.get(c, 0) + 1
 
         for right in range(len(s)):
             c = s[right]
             if c in d:
                 d[c]-=1
                 if d[c] >=0:
                     # good match
                     totalMatch +=1
 
                     if left == -1:
                         left = right
 
                     #find a sustring
                     if totalMatch == len(t):
                         if result == "" or len(result) > right - left:
                             result = s[left: right+1]
 
                         d[s[left]]+=1
                         totalMatch -=1
                         while left<right:
                             left +=1
 
                             if s[left] in d:
                                 if d[s[left]] <0:
                                     # skip over matched letter
                                     d[s[left]] +=1
                                 else:
                                     break
                 
                 elif c == s[left]:
                     d[c]+=1
                     while left < right:
                         left +=1
                         # skip over matched letter
                         if s[left] in d:
                             if d[s[left]] <0:
                                 d[s[left]] +=1
                             else:
                                 break
         return result