Easy Explanation | C++ | Sliding Window
Intuition\nFirst i break string into parts such that no two adjacent chars \nhave diff more than 2 \n\nnow for each broken part i calculate answer and add them 
# Intuition\nFirst i break string into parts such that no two adjacent chars \nhave diff more than 2 \n\nnow for each broken part i calculate answer and add them to final answer.. \n\nCalculating answer for each part...\n\nnow i have to count substrings such that they have each character k times..\n\nstring can contain of only 26 unique characters.. \n\nif string contains of j unique character\'s, it\'s len should be k * j \n\nso i check all strings of len 1 * k to 26 * k \n\nnow in the string of len j * k \n\ni check using freq array that there are j characters with freq k.. \n\ni use sliding window to check substrings of each len starting with 1 * k  \n\nPS: Please correct anything you find wrong..\n\n\n# Code\n```\n\nclass Solution {\npublic:\n    // checking the frequency vector so that there \n    // are j characters and each character occurs k times..\n    bool check(vector<int> & freq, int &j, int &k)\n    {\n        int ct = 0;\n        for(int i = 0; i < freq.size();i++)\n        {\n            if (freq[i] == 0) continue;\n            if (freq[i] != k) return false;\n            else ct++;\n        }\n        if (ct > j) return false;\n        return true;\n    }\n    long long int func(string & s, int &k)\n    {\n        long long int count = 0;\n        int n = s.length();\n        for(int j = 1; j <= 26;j++)\n        {\n            int len = k * j;\n            vector<int> freq(26,0);\n            if (len > n) break;\n            // using sliding window to check each substring of length = len..\n            for(int i = 0; i < len;i++)\n            {\n                freq[s[i] - \'a\']++;\n            }\n            if (check(freq,j,k)) count++;\n            for(int i = len;i < n;i++)\n            {\n                char prev = s[i - len];\n                char next = s[i];\n                freq[prev - \'a\']--;\n                freq[next  - \'a\']++;\n                if (check(freq,j,k)) count++;\n            }\n        }\n        return count;\n    }\n    int countCompleteSubstrings(string word, int k) {\n        long long int  ans = 0;\n        string result = "";\n        int n = word.length();\n        for(int i =0; i < n;i++)\n        {\n            result += word[i];\n            if (i <= n - 2)\n            {\n                if (abs(word[i] - word[i + 1]) > 2)\n                {\n                    ans += func(result,k);\n                    result = "";\n                }\n            }\n        }\n        ans += func(result,k);\n        return ans;\n    }\n};\n/*\nintution : \n\nfirst i break string into parts such that no two adjacent chars \nhave diff more than 2 \n\nnow for each broken part i calculate answer and add them to final answer.. \n\nCalculating answer for each part...\n\nnow i have to count substrings such that they have each character k times..\n\nstring can contain of only 26 unique characters.. \n\nif string contains of j unique character\'s, it\'s len should be k * j \n\nso i check all strings of len 1 * k to 26 * k \n\nnow in the string of len j * k \n\ni check using freq array that there are j characters with freq k.. \n\ni use sliding window to check substrings of each len starting with 1 * k \n\n\n*/\n```
['C++']