Sliding Window || Similar to Aditya Verma's Approach
Reference Aditya Verma\'s video posted in comments.\n# Code\ncpp []\nclass Solution {\npublic:\n    long long validSubstringCount(string word1, string word2) {\
Reference Aditya Verma\'s video posted in comments.\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long validSubstringCount(string word1, string word2) {\n        vector<int> freq(26, 0);\n        int cnt = 0;\n        for (char ch : word2) {\n            if (freq[ch - \'a\'] == 0) {\n                cnt++;\n            }\n            freq[ch - \'a\']++;\n        }\n        long long j = 0, ans = 0;\n        for (long long i = 0; i < word1.size(); i++) {\n            if (--freq[word1[i] - \'a\'] == 0) {\n                cnt--;\n            }\n            while (cnt == 0) {\n                ans += (word1.size() - i);\n                if (++freq[word1[j] - \'a\'] == 1) {\n                    cnt++;\n                }\n                j++;\n            }\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'Sliding Window', 'C++']