C++ | Sliding Window | Easy Approach
\nclass Solution {\npublic:\n    vector<vector<int>>vec;\n    int func(int x,int k,string s)// Standard sliding window approach counting substrings with length 
```\nclass Solution {\npublic:\n    vector<vector<int>>vec;\n    int func(int x,int k,string s)// Standard sliding window approach counting substrings with length x*k with each character occuring exactly k times \n\t{  \n        int ans=0;\n        for(auto &it:vec){\n            int j=it[0],e=it[1];\n            int cntk=0;\n            unordered_map<char,int>mp;\n            for(int i=it[0];j<=e;j++)\n\t\t\t{\n                mp[s[j]]++;\n                if(mp[s[j]]==k) cntk++;\n                if(j-i+1>(x*k)){\n                    mp[s[i]]--;\n                    if(mp[s[i]]==(k-1)) cntk--;\n                    if(mp[s[i]]==0) mp.erase(s[i]);\n                    i++;\n                }\n                if(mp.size()==x && cntk==mp.size()) ans++;\n            }\n\t\t}\n        return ans;\n    }\n    int countCompleteSubstrings(string word, int k) {\n        vector<int>v;\n        string s=word;\n        for(int i=1;i<s.size();i++){\n            if(i<s.size() && abs(s[i]-s[i-1])>2) v.push_back(i);\n        }\n        int st=0,e=s.size()-1;\n        for(auto &it:v){\n            if(st<=it-1)\n            vec.push_back({st,it-1});\n            st=it;\n        }\n       if(st<=e)\n       vec.push_back({st,e}); // vec will store ranges in which substring can be formed\n       int ans=0;\n       for(int i=1;i<=26 && i*k<=s.size();i++){\n           ans+=func(i,k,word); // func will return number of substrings with i different characters each occuring exactly k times\n       }\n       return ans;\n    }\n};\n```
['Sliding Window', 'C++']