[Python 3] beats 100%, O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem can be rephrased as, what is the minimum length of a contiguous substring t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem can be rephrased as, what is the minimum length of a contiguous substring that can be taken out to make T a generic substring of S.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution:\n    def minimumScore(self, S: str, T: str) -> int:\n        lS,lT = len(S),len(T)\n        setS,setT = set(S),set(T)\n        setTMS = setT-setS\n        \n        s = 0\n        listL = []\n        for t in T:\n            if t in setTMS:     break\n            while s<lS and S[s]!=t:\n                s += 1\n            if s==len(S):       break\n            listL.append(s)\n            s += 1\n        if len(listL) == lT:            return 0\n        \n        s = lS-1\n        listR = []\n        for t in T[::-1]:\n            if t in setTMS:     break\n            while s>=0 and S[s]!=t:\n                s -= 1\n            if s==-1:       break\n            listR.append(s)\n            s -= 1\n        listR = listR[::-1]\n        if listL and listR and listL[-1]<listR[0] or not listL or not listR:\n            return lT-len(listR)-len(listL)\n            \n        l = len(listL)-1\n        retV = lT - max(len(listL), len(listR))\n        for i,r in enumerate(listR[::-1]):\n            while l>=0 and listL[l]>=r:\n                l -= 1\n            if l==-1:   break\n            retV = min(retV, lT-i-1-l-1)\n        return retV\n        \n        \n        \n\n```
['Python3']