Two pointer | Sliding Window | Easy solution
Approach:\n1. Total Number of Substrings:\n\t1. The total number of substrings for a string of length n is calculated using the formula: (n*(n+1))/2\n2. Identif
Approach:\n1. Total Number of Substrings:\n\t1. The total number of substrings for a string of length n is calculated using the formula: (n*(n+1))/2\n2. Identifying Impossible Substrings\n3. Final Step:\n\t1. Subtract the number of impossible substrings from the total number of substrings to get the desired result.\n\n```\nclass Solution {\npublic:\n    \n    long long validSubstringCount(string w1, string w2) {\n        long long n = w1.size();\n        unordered_map<char,int>freq1;\n        unordered_map<char,int>freq2;\n        for(int i=0;i<w2.size();i++){\n            freq2[w2[i]]++;\n        }\n        long long ans = (n*(n+1))/2;\n        long long curr =0;\n        int i =0,j=0;\n        while(j<n){\n            if(freq2.count(w1[j]))\n              freq1[w1[j]]++;\n            bool poss  = true;\n            auto it = freq2.begin();\n            while(it!=freq2.end()){\n                if(it->second>freq1[it->first]){\n                    poss = false;\n                    break;\n                }\n                it++;\n            }\n            if(poss){\n                while(i<=j){\n                    int curr = w1[i];\n                    if(freq2.count(curr)){\n                        freq1[curr]--;   \n                    }\n                     i++;\n                if(freq2.count(curr) && freq2[curr]>freq1[curr])\n                 break;\n                   \n                   \n                }\n            }\n            \n            long long diff = j-i+1;\n            curr= curr + diff;\n            j++;\n\n        }\n        return ans-curr;\n        \n    }\n};\n```
['C']