C++ Solution With explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n1) Each character should come exactly k time. There can be 1,2,3,4,5,6,7_ _ _ , 26 ch
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n1) Each character should come **exactly** k time. There can be 1,2,3,4,5,6,7_ _ _ , 26 character can be there. So the possible length of the substring can be k, 2k, 3k, 4k, 5k, 6k, 7k _ _ _ _ _ _ _, 26k.\n2) Iterate over all the length and count number of substring of each length that is satisfying the conditions.\n3) In order to check a substring is valid for that two conditions are there , First the frequency of each character should be either k or 0 and Second adjacent character difference should be atmost 2.\n\n# Code\n```\nclass Solution {\npublic:\n\n    int helper(string word, int len, vector<vector<int>>& prefixCnt, int k) {\n        \n        int n = word.size();\n        int dp[n + 1];\n        for(int i = 0; i < n; i++) {\n            dp[i] = 1;\n        }\n\n        for(int i = 1; i < n; i++) {\n            int prevVal = word[i - 1] - \'a\';\n            int currVal = word[i] - \'a\';\n            if(abs(currVal - prevVal) <= 2) {\n                dp[i] += dp[i - 1]; \n            }\n        }\n\n        int cnt = 0;\n        for(int i = 0; i < n; i++) {\n            \n            bool can = true;\n            \n            int j = i - len;\n            if(j < 0) {\n                for(int ch = 0; ch < 26; ch++) {\n                    int r = prefixCnt[i][ch];\n                    if(r == 0) continue;\n                    if(r != k) {\n                        can = false;\n                    }\n                }\n            } else {\n                for(int ch = 0; ch < 26; ch++) {\n                    int l = prefixCnt[j][ch];\n                    int r = prefixCnt[i][ch];\n                    if(r - l == 0) continue;\n                    if(r - l != k) {\n                        can = false;\n                    }\n                }\n            }\n\n            if(can && dp[i] >= len) {\n                cnt++;\n            }\n\n        }\n\n        return cnt;\n\n    }\n\n\n    int countCompleteSubstrings(string word, int k) {\n        \n        int n = word.size();\n\n        vector<vector<int>>prefixCnt(n, vector<int>(26, 0));\n        for(int i = 0; i < n; i++) {\n            int currVal = word[i] - \'a\';\n            if(i == 0) {\n                for(int j = 0; j < 26; j++) {\n                    if(currVal == j) {\n                        prefixCnt[i][j] += 1;\n                    } else {\n                        prefixCnt[i][j] += 0;\n                    }\n                }\n            } else {\n                for(int j = 0; j < 26; j++) {\n                    if(currVal == j) {\n                        prefixCnt[i][j] = prefixCnt[i - 1][j] + 1;\n                    } else {\n                        prefixCnt[i][j] = prefixCnt[i - 1][j];\n                    }\n                }\n            }\n        }\n\n\n\n\n        int ans = 0;\n        for(int i = 1; i <= 26 ; i++) {\n            int len = k * i;\n            if(len > n) break;\n            int subLen = helper(word, len, prefixCnt, k);\n            cout<<subLen<<" ";\n            ans += subLen;\n        }\n\n        return ans;\n\n    }\n};\n```
['C++']