Sliding Window [Template]
Intuition\n Describe your first thoughts on how to solve this problem. \n sliding window \n target is the word2 set\n\n# Approach\n start from right = 0\n updat
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* sliding window \n* target is the word2 set\n\n# Approach\n* start from `right = 0`\n* update the word status map and see if we have enough word2 set.\n* try to move left and add `len(word1) - right`.\n* update the status map since we are moving left pointer.\n* break the internal while when we don\'t have enough characters.\n* move `right += 1`\n\n# Code\n```python3 []\nfrom collections import defaultdict\nclass Solution:\n    def validSubstringCount(self, word1: str, word2: str) -> int:\n        if not word2 or not word1:\n            return 0\n        char_freq = defaultdict(int)\n        remain = set(word2)\n        word2_set = set(word2)\n        if len(word1) <  len(word2):\n            return 0\n        for w in word2:\n            char_freq[w] += 1\n\n        res = 0\n        l, r = 0, 0\n        while r < len(word1):\n            if word1[r] in word2_set:\n                char_freq[word1[r]] -= 1\n                if char_freq[word1[r]] == 0:\n                    remain.remove(word1[r])\n            \n            while len(remain) == 0 and l <= r:\n                res += len(word1) - r\n                if word1[l] in word2_set:\n                    char_freq[word1[l]] += 1\n                    if char_freq[word1[l]] == 1:\n                        remain.add(word1[l])\n                l += 1\n            r += 1\n        return res\n\n\n```
['Python3']