Easy Sliding Window | C++ | Simple to understand
\nclass Solution {\npublic:\n    long long validSubstringCount(string word1, string word2) {\n        long long ans=0;\n        int i=0,j=0;\n        unordered_
```\nclass Solution {\npublic:\n    long long validSubstringCount(string word1, string word2) {\n        long long ans=0;\n        int i=0,j=0;\n        unordered_map<int,int> freqSoFar, word2Count;\n        for(auto ch: word2) {\n            word2Count[ch]++;\n            freqSoFar[ch]++;\n        }\n        \n        while(j<word1.size()){\n            freqSoFar[word1[j]]--;\n            if(freqSoFar[word1[j]]==0){\n                word2Count.erase(word1[j]);\n            }\n            \n            while(word2Count.size()==0){\n                ans+=word1.size()-j;\n                freqSoFar[word1[i]]++;\n                if(freqSoFar[word1[i]]>0){\n                    word2Count[word1[i]]++;\n                    i++;\n                    break;\n                }\n                i++;\n            }\n            j++;\n        }\n        return ans;\n    }\n};\n```
[]