Sliding window | C++
Complexity\n- Time complexity: O(n)\n# Code\ncpp []\n#define ll long long int\n\nclass Solution {\npublic:\n    bool chk(vector<int>&w1cnt, vector<int>&w2cnt){\
# Complexity\n- Time complexity: $$O(n)$$\n# Code\n```cpp []\n#define ll long long int\n\nclass Solution {\npublic:\n    bool chk(vector<int>&w1cnt, vector<int>&w2cnt){\n        for(int i=0;i<26;i++)if(w2cnt[i]>w1cnt[i])return 0;\n        return 1;\n    }\n\n    long long validSubstringCount(string w1, string w2) {\n        vector<int>w1cnt(26, 0), w2cnt(26, 0);\n        for(auto c:w2)w2cnt[c-\'a\']++;\n        ll ans=0;\n        int l=0, r=0, n=w1.length();\n        while(r<n){\n            w1cnt[w1[r]-\'a\']++;\n            while(chk(w1cnt, w2cnt)){\n                ans+=(n-r);\n                w1cnt[w1[l]-\'a\']--;\n                l++;\n            }\n            r++;\n        }\n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']