Using Unordered maps
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    bool check(unordered_map<char,int> & mp){\n        for(auto m: mp){\n            if(m.second>0) return false;
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool check(unordered_map<char,int> & mp){\n        for(auto m: mp){\n            if(m.second>0) return false;\n        }\n        return true;\n    }\n    long long validSubstringCount(string word1, string word2) {\n        long long count = 0;\n        int i=0,j=0;\n        int n = word1.size(),m = word2.size();\n        unordered_map<char,int> mp;\n        for(int k=0;k<m;k++){\n            mp[word2[k]]++;\n        }\n        while(j<n){\n            if(mp.find(word1[j])!=mp.end()) {\n                mp[word1[j]]--;\n            }\n            while(check(mp) && i<=j){\n                count += n-j;\n               if(mp.find(word1[i])!=mp.end()) mp[word1[i]]++;\n               i++;\n            }\n\n            j++;\n\n\n        }\n\n        return count;\n\n        \n    }\n};\n```
['C++']