Python Two Pointers
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(2n1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def validSubstringCount(self, word1: str, word2: str) -> int:\n        n1, n2 = len(word1), len(word2)\n        l, r = 0, 0\n        f_2, f_1 = [0]*26, [0]*26\n        m = n2\n        ans = 0\n        for c in word2:\n            f_2[ord(c)-ord(\'a\')] += 1\n\n        while r < n1:\n            i = ord(word1[r])-ord(\'a\')\n            f_1[i] += 1\n            if f_2[i] != 0 and f_2[i] >= f_1[i] :\n                m -= 1\n            while m == 0:\n                ans += n1-r\n                #exclude left and move left\n                i_e = ord(word1[l])-ord(\'a\')\n                f_1[i_e] -= 1\n                if f_2[i_e] != 0 and f_2[i_e] > f_1[i_e] :\n                    m += 1\n                l += 1\n            r += 1\n        return ans\n\n\n\n```
['Python3']