Python Sliding window O(N*26)
The idea is that the size of the window we are looking for will be a multiple of k and we only have 26 character possiblities so where k = 1 we would check size
The idea is that the size of the window we are looking for will be a multiple of k and we only have 26 character possiblities so where k = 1 we would check size 1,2,3,4,5,6...26 since the largest window is 1 of each character. For k = 2 we would try 2,4,6,8,10... since the largest we can have is 2 of each character so 52. To solve the no 2 characters next to eachother differ by 2 I just use a prefix array where if they differ I increase the prefix which ends up grouping the values so its easy to just check if our right and left pointer are in the same group. Finally to see if all the values are equal to k I use an array to count and an integer that when set to 0 or k subtracts and when set otherwise increments so that if that integer is k we know they are all valid.\n\nWithout using a prefix array to store the counts.\n\n```py\nclass Solution:\n    def countCompleteSubstrings(self, word: str, key: int) -> int:\n\n        def charDist(a,b):\n            return abs(ord(a) - ord(b)) <= 2\n        \n        valid = [0] * len(word)\n        \n        for i in range(1,len(word)):\n            if not charDist(word[i-1], word[i]):\n                valid[i] = valid[i-1] + 1\n            else:\n                valid[i] = valid[i-1]\n        \n        mp = defaultdict(int)\n        for char in \'abcdefghijklmnopqrstuvwxyz\':\n            mp[char] = ord(char) - ord(\'a\')\n        \n        res = 0\n        for i in range(1,27):\n            \n            val = key * i\n            if key * i > len(word):\n                break\n            arr = [0] * 26\n            bit = 0\n            for j in range(len(word)):\n                \n                v = mp[word[j]]\n                if arr[v] == key or arr[v] == 0:\n                    bit += 1\n                    \n                arr[v] += 1\n                \n                if arr[v] == key:\n                    bit -=1\n                    \n                if j >= val:\n                    v2 = mp[word[j-val]]\n                    \n                    if arr[v2] == key:\n                        bit += 1\n                    arr[v2] -=1\n                    \n                    if arr[v2] == key or arr[v2] == 0:\n                        bit -=1\n                     \n                \n                if j >= val-1 and valid[j-val+1] == valid[j] and bit == 0:\n                    res += 1\n                        \n        return res\n```\n\t\n\t#With the prefix to store counts\n\t\n```py\n\tclass Solution:\n    def countCompleteSubstrings(self, word: str, key: int) -> int:\n\n        def charDist(a,b):\n            return abs(ord(a) - ord(b)) <= 2\n        \n        valid = [0] * len(word)\n        \n        mp = defaultdict(int)\n        for char in \'abcdefghijklmnopqrstuvwxyz\':\n            mp[char] = ord(char) - ord(\'a\')\n            \n        for i in range(1,len(word)):\n            if not charDist(word[i-1], word[i]):\n                valid[i] = valid[i-1] + 1\n            else:\n                valid[i] = valid[i-1]\n            \n        prefixMp = defaultdict(list)\n        arr = [0] * 26\n        \n        prefixMp[0] = arr.copy()\n        \n        for i in range(len(word)):\n            arr[mp[word[i]]] += 1\n            prefixMp[i+1] = arr.copy()\n        \n\n        res = 0\n        for i in range(1,27):\n            \n            val = key * i\n            \n            if key * i > len(word):\n                break\n                \n            arr = prefixMp[val]\n            bit = 0\n            for v in arr:\n                if v > 0 and v != key:\n                    bit += 1\n                    \n            if valid[val-val] == valid[val-1] and bit == 0:\n                res +=1\n                \n            for j in range(val, len(word)):\n                \n                v = mp[word[j]]\n                if arr[v] == key or arr[v] == 0:\n                    bit += 1\n                    \n                arr[v] += 1\n                \n                if arr[v] == key:\n                    bit -=1\n                    \n                if j >= val:\n                    v2 = mp[word[j-val]]\n                    \n                    if arr[v2] == key:\n                        bit += 1\n                    arr[v2] -=1\n                    \n                    if arr[v2] == key or arr[v2] == 0:\n                        bit -=1\n                     \n                \n                if valid[j-val+1] == valid[j] and bit == 0:\n                    res += 1\n                        \n        return res\n```\n\n\t
['Sliding Window', 'Python']