[C++] sliding window.
\ncpp []\nclass Solution {\n    bool valid(const vector<int>& cnt, const vector<int>& pattern) {\n        bool ret = true;\n        for (int i = 0; i < pattern.
\n```cpp []\nclass Solution {\n    bool valid(const vector<int>& cnt, const vector<int>& pattern) {\n        bool ret = true;\n        for (int i = 0; i < pattern.size(); ++i) {\n            if (cnt[i] < pattern[i]) {\n                ret = false;\n                break;\n            }\n        }\n\n        return ret;\n    }\npublic:\n    long long validSubstringCount(string word1, string word2) {\n        vector<int> pattern(26);\n        for (auto c : word2) {\n            ++pattern[c - \'a\'];\n        }\n\n        vector<int> cnt(26);\n        int m = word2.size();\n        int n = word1.size();\n        long long ans = 0;\n        for (int i = 0, j = 0; j < n;) {\n            ++cnt[word1[j] - \'a\'];\n\n            if (valid(cnt, pattern)) {\n                ans += n - j;\n                --cnt[word1[i] - \'a\'];\n                --cnt[word1[j] - \'a\'];\n                ++i;\n            } else {\n                ++j;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']