Python Code
Intuition\n Describe your first thoughts on how to solve this problem. \n0. Sliding window is needed. The brute force time complexity is O(n^3), using sliding w
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n0. Sliding window is needed. The brute force time complexity is O(n^3), using sliding window, the time complexity should be O(n*26)\n\n1. When we see a "break point," meaning the difference between the letter and the previous one is larger than 2, we separate it.\n2. ```\n    count = Counter(s[:l])\n    freq = Counter(count.values())\n    if freq[k] == i: res += 1\n    ```\n    This is the key for this question, we not only maintain a counter, we also have a frequency. Which is counter for counts. That helps check validity in O(1).\n \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(26*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfrom collections import Counter\n\nclass Solution:\n    def countCompleteSubstrings(self, word: str, k: int) -> int:\n        \n        def calc(s):\n            res = 0\n            for i in range(1, 27):\n                l = i * k # try out this length\n                if l > len(s): \n                    break\n                count = Counter(s[:l])\n                freq = Counter(count.values())\n                if freq[k] == i: res += 1\n\n                for idx in range(l, len(s)):\n                    freq[count[s[idx]]] -= 1\n                    count[s[idx]] += 1\n                    freq[count[s[idx]]] += 1\n\n                    freq[count[s[idx-l]]] -= 1\n                    count[s[idx-l]] -= 1\n                    freq[count[s[idx-l]]] += 1\n\n                    if freq[k] == i: \n                        res += 1\n            return res\n\n        index = 0\n        ans = 0\n        n = len(word)\n        for i in range(1, n):\n            if abs(ord(word[i]) - ord(word[i-1])) > 2:\n                ans += calc(word[index:i])\n                index = i \n                \n        ans += calc(word[index:])\n\n        return ans\n```
['Python3']