BEATS 100% || EASY || SLIDING WINDOW
\n\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int solve(int start, int end, string &word, int k) {\n        int result = 0;\n        for(int chars = 1; c
\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int solve(int start, int end, string &word, int k) {\n        int result = 0;\n        for(int chars = 1; chars <= 26 && chars*k <= end-start+1; chars++) {\n\n            vector<int> count(26, 0);\n            int goodChars = 0; //How many chars are of frequency k\n\n            //Now do a sliding window\n            int i = start;\n            int windowLength = chars*k;\n            for(int j = start; j <= end; j++) {\n                char ch = word[j];\n\n                count[ch - \'a\']++;\n                if(count[ch - \'a\'] == k) {\n                    goodChars++;\n                } else if(count[ch - \'a\'] == k+1) {\n                    goodChars--;\n                }\n\n                if(j-i+1 > windowLength) { //Need to shift window right\n                    if(count[word[i] - \'a\'] == k) {\n                        goodChars--;\n                    } else if(count[word[i] - \'a\'] == k+1) {\n                        goodChars++;\n                    }\n                    count[word[i] - \'a\']--;\n                    i++;\n                }\n\n                if(goodChars == chars) {\n                    result++;\n                }\n\n            }\n\n        }\n\n        return result;\n\n    }\n\n    int countCompleteSubstrings(string word, int k) {\n        int n = word.length();\n\n        int result = 0;\n        int last = 0;\n\n        for(int i = 1; i <= n; i++) {\n            if(i == n || abs(word[i] - word[i-1]) > 2) { //satisying condition 2\n                result += solve(last, i-1, word, k); //condition 1\n                last = i;\n            }\n        }\n\n        return result;\n    }\n};\n```
['C++']