Python sliding window, readable and easy to understand
Python sliding window, readable and easy to understand\n\n\t\ttarget_cnt = collections.Counter(word2)\n        cnt = collections.Counter()\n        \n        # 
Python sliding window, readable and easy to understand\n\n\t\ttarget_cnt = collections.Counter(word2)\n        cnt = collections.Counter()\n        \n        # Sliding window\n        i = 0\n        res = 0\n        matched = 0\n        for j, c in enumerate(word1):\n            cnt[c] += 1\n            if cnt[c] == target_cnt[c]:\n                matched += 1\n            \n            # shrink the window if possible\n            while i <= j and cnt[word1[i]] > target_cnt[word1[i]]:\n                cnt[word1[i]] -= 1\n                i += 1\n    \n            # if condition is met, accumulate the count\n            if matched == len(target_cnt):\n                res += i + 1\n            \n        return res
[]