Sliding window
Intuition\nUtilize sliding window\n\n# Code\ncpp []\nclass Solution {\npublic:\n    bool isValid(vector<int>& f1, vector<int>& f2) {\n        for(int i = 0; i <
# Intuition\nUtilize sliding window\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool isValid(vector<int>& f1, vector<int>& f2) {\n        for(int i = 0; i < 26; i++) {\n            if(f1[i] > f2[i]) return false;\n        }\n        return true;\n    }\n\n    long long validSubstringCount(string word1, string word2) {\n        if(word1.size() < word2.size()) return 0;\n        vector<int> freq1(26, 0);\n        for(auto &it : word2) freq1[it-\'a\']++;\n\n        vector<int> freq2(26, 0);\n        long long ans = 0;\n        int start = 0;\n        for(int i = 0; i < word1.size(); i++) {\n            freq2[word1[i]-\'a\']++;\n            while(isValid(freq1, freq2)) {\n                ans += word1.size()-i;\n                freq2[word1[start]-\'a\']--;\n                start++;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']