Share my neat and easy-understand python solution in O(n)
class Solution(object):\n        '''\n        b -- begin index of window; e -- end index of window.\n        example: S="acbbaca", T="aba"\n        \n        0 
    class Solution(object):\n        '''\n        b -- begin index of window; e -- end index of window.\n        example: S="acbbaca", T="aba"\n        \n        0 1 2 3 4 5 6\n        a c b b a c a\n        \n        initially, b=e=0\n        a:2\n        b:1\n        pc=2 (positive count. pc>0 indicates that there are element in T yet to find, that is, current window is not legit.)\n        \n        expanding:\n        b=0,e=0  b=0,e=2  b=0,e=3                 b=0,e=4  b=0,e=6\n        a:1      a:1      a:1                     a:0      a:-1     \n        b:1      b:0      b:-1(more b than need)  b:-1     b:-1\n        pc=2     pc=1     pc=1                    pc=0     pc=0\n                                                  [0:4]    [0:6]\n        \n        shrinking:\n        b=2,e=6  b=3,e=6  \n        a:0      a:0\n        b:-1     b:0\n        pc=0     pc=0\n        [2:6]    [3:6]\n        \n        then expanding... and so on.\n        '''\n        def minWindow(self, s, t):\n            """\n            :type s: str\n            :type t: str\n            :rtype: str\n            """\n            m = {}\n            pc = 0  # positive count\n            for c in t:\n                if not c in m:\n                    m[c] = 1\n                    pc += 1\n                else:\n                    m[c] += 1\n            \n            b = e = 0\n            w = [-1, -1]  # ret str = [w[0], w[1]), left inclusive, right not.\n            while True:\n                if e<len(s) and b<=e and pc>0:  # expand\n                    if s[e] in m:  # what if including char @ index e?\n                        m[s[e]] -= 1\n                        if m[s[e]]==0:  # previously m[s[e]]==1, of course pc-=1\n                            pc -= 1\n                    e += 1\n                elif b<=e and pc==0:  # shrink\n                    if w[0]==-1 or e-b<w[1]-w[0]:\n                        w[0], w[1] = b, e\n                    if s[b] in m:  # what if excluding char @ index b?\n                        m[s[b]] += 1\n                        if m[s[b]] == 1:  # previously m[s[b]]==0, of course pc+=1\n                            pc += 1\n                    b += 1\n                else:\n                    break\n            \n            if w[0]==-1:\n                return ""\n            else:\n                return s[w[0]:w[1]]
['Python']