Sliding Window | Python
Complexity\n- Time complexity: O(n+m) where n = len(word1), m=len(word2)\n\n- Space complexity: O(n+m)\n\n# Code\npython3 []\nclass Solution:\n    def validSubs
# Complexity\n- Time complexity: O(n+m) where n = len(word1), m=len(word2)\n\n- Space complexity: O(n+m)\n\n# Code\n```python3 []\nclass Solution:\n    def validSubstringCount(self, word1: str, word2: str) -> int:\n        countW2 = Counter(word2)\n        need = len(countW2)\n        have = 0\n        ans = 0\n        l = 0\n        window = defaultdict(int)\n        \n        for r,c in enumerate(word1):\n            window[c]+=1\n            if c in countW2 and window[c]==countW2[c]:\n                have+=1\n                while have==need:\n                    ans+=len(word1)-r\n                    window[word1[l]]-=1\n                    if word1[l] in countW2 and window[word1[l]]<countW2[word1[l]]:\n                        have-=1\n                    l+=1\n        \n        return ans\n\n```
['Sliding Window', 'Python', 'Python3']