C++ | beats  100% | easy to understand
Intuition\n\nIntution of problem is to find valid substring with satisfy given condition.\n Describe your first thoughts on how to solve this problem. \n\n# App
# Intuition\n\nIntution of problem is to find valid substring with satisfy given condition.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n1. If diff between `ith` and `(i+1)th` char is greater than k. then this is our break point we can devide string in 2 parts.\n2. A substring can valid if its len it `k*i` (i is interger) why? because as given substring must contain every char exaclty k time so if there are `i` char than len would be `k*i`\n3. so we can apply sliding window for every `k*i` len subarray.\n4. As we have only `26` char so max window length can be `k*26` ie ..i.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n*26)$$\nouter loop run 26 time and inner at max n time \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\nas taking constant dp vector and curr string\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n--------------------------\n\n# please upvote if you feel it is helpful\n------------------------------------------\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(vector<int>&dp, int k){\n        for(int i=0;i<26;i++){\n            if(dp[i]==0) continue;\n            else if(dp[i]!=k){\n                return false;\n            }\n        }\n        return true;\n    }\n    long long calculate(string &s, int k){\n\n        int n = s.size();\n        long long ans=0;\n\n        for(int i=1;i<=26;i++){\n            int len = k*i;\n            if(len>n) break;\n            vector<int>dp(26,0);\n\n            for(int j=0;j<n;j++){\n                dp[s[j]-\'a\']++;\n                if((j+1)>=len){\n                    if(check(dp,k)){\n                        ans++;\n                    }\n                    dp[s[j+1-len]-\'a\']--;\n                }\n            }\n        }\n        return ans;\n    }\n    int countCompleteSubstrings(string word, int k) {\n        \n        int n = word.size();\n        long long ans = 0;\n        string curr = "";\n        for(int i=0;i<n;i++){\n            \n            curr.push_back(word[i]);\n            if(i<=n-2 and abs(word[i]-word[i+1])>2){\n                ans+= calculate(curr, k);\n                curr="";\n            }\n        }\n        ans+= calculate(curr, k);        \n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']