Sliding Window
Approach\n Describe your approach to solving the problem. \nBecause the difference between two adjacent characters is at most 2. We divide word by the constrain
# Approach\n<!-- Describe your approach to solving the problem. -->\nBecause the difference between two adjacent characters is at most 2. We divide `word` by the constraint into several substrings. We calculate a substring\'s complete count in function `getComplete()`.\n# Complexity\n- Time complexity: $$O(n)$$, or $$O(26*26*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$, or $$O(26)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n    public int CountCompleteSubstrings(string word, int k)\n    {\n        var res = 0;\n        var start = 0;\n        while (start < word.Length)\n        {\n            var end = start;\n            for (int j = start + 1; j < word.Length; j++)\n            {\n                if (Math.Abs(word[j] - word[j - 1]) <= 2)\n                {\n                    end = j;\n                }\n                else\n                {\n                    break;\n                }\n            }\n            res += getComplete(word[start..(end + 1)], k);\n            start = end + 1;\n        }\n        return res;\n    }\n    int getComplete(string s, int k)\n    {\n        var res = 0;\n        for (int i = 1; i <= 26; i++)\n        {\n            var size = i * k;\n            if (size > s.Length) break;\n            var charCount = new int[26];\n            for (int j = 0; j < size; j++)\n            {\n                charCount[s[j] - \'a\']++;\n            }\n            if (charCount.All(x => x == k || x == 0))\n            {\n                res++;\n            }\n            for (int j = size; j < s.Length; j++)\n            {\n                charCount[s[j] - \'a\']++;\n                charCount[s[j - size] - \'a\']--;\n                if (charCount.All(x => x == k || x == 0))\n                {\n                    res++;\n                }\n            }\n        }\n        return res;\n    }\n}\n```
['C#']