Efficient Sliding Window Solution
First we have to find valid strings which satisfy second condition.\n\n2. Just because we need k times characters in string, valid legths will be 1 k, 2 k, 3* k
1. First we have to find valid strings which satisfy second condition.\n\n2. Just because we need k times characters in string, valid legths will be 1* k, 2* k, 3* k...\n\n3. Now in every valid string we have to check frequency.\n\n4. We can use standard sliding window technique and if any character appear more than k time or length of our counter is not equal to unique characters we can continue otherwise increase result.\n\n5. You check that if we have 2 unique char in string and k = 2 that means length should be k * l = 4 means our counter length should be 2.\n\n6. For example: aabb, k = 2 Counter{a: 2, b: 2} and each char freq is 2.\n# Code\n```\nclass Solution:\n    def countCompleteSubstrings(self, w: str, k: int) -> int:\n        def calc(s):\n            res = 0\n            v = len(s)\n            for i in range(1, 27):\n                if i * k > v: break\n                l = i * k\n                \n                cnt = Counter()\n                left = 0\n\n                for right in range(len(s)):\n                    cnt[s[right]] += 1\n                    if right - left + 1 == l:\n                        for val in cnt.values():\n                            if val > k:\n                                break\n                        else:\n                            if len(cnt) == i:\n                                #print(cnt, i)\n                                res += 1\n                        cnt[s[left]] -= 1\n                        if cnt[s[left]] == 0:\n                            del cnt[s[left]]\n                        left += 1\n            return res\n        \n        idx = 0\n        ans = 0\n        n = len(w)\n        for i in range(1, n):\n            if abs(ord(w[i]) - ord(w[i-1])) > 2:\n                ans += calc(w[idx:i])\n                idx = i\n        ans += calc(w[idx:])\n        return ans\n```
['Python3']