
class Solution:
    def minWindow(self, s: str, t: str) -> str:
        tdict = dict()
        results = ""
        for char in t:
            if char not in tdict:
                tdict[char] = 1
            else:
                tdict[char] +=1

        left =0 
        right = 0
        minlen = float('inf')
        running = dict()
        found = False
       
        while right < len(s):
            #print(running, left, right)

            #Adding to runnign dictionary
            successflag = True
            if s[right] not in running:
                running[s[right]] = 1
            else:
                running[s[right]] += 1


            #Checking for result condition
            for key, value in tdict.items():
                if key not in running:
                    successflag = False
                elif running[key] < value:
                    successflag = False

            
            if successflag:
                #We found a window that matches. Now we need to trim excess letters
                #We also need to trim extra filler letters as well as extra copies of letters in T
                while left < right and ((s[left] in tdict and running[s[left]] > tdict[s[left]]) or s[left] not in tdict):
                    #print(left, right, "prune")
                    if running[s[left]] == 1:
                        del running[s[left]]
                    else:
                        running[s[left]] -=1

                    left += 1

                found = True
                if len(s[left:right+1]) < minlen:
                    minlen = len(s[left:right+1])
                    results = s[left:right+1]

            right +=1

        #print(results)
        if len(results) == 0:
            return ""
        else:
            return results


        