Java | Sliding Window | Beats 100%
Code\n\nclass Solution {\n    public int countCompleteSubstrings(String word, int k) {\n        int i = 0;\n        int res = 0;\n        while (i < word.length
# Code\n```\nclass Solution {\n    public int countCompleteSubstrings(String word, int k) {\n        int i = 0;\n        int res = 0;\n        while (i < word.length()) {\n            int j = i+1;\n            while (j < word.length() && Math.abs(word.charAt(j)-word.charAt(j-1)) < 3) {\n                j++;\n            }\n            res += calc(i, j-1, k, word);\n            i = j;\n        }\n        \n        return res;\n    }\n    \n    public int calc(int start, int end, int k, String word) {\n        int res = 0;\n        for (int i = 1; i <= 26; i++) {\n            int length = i*k;\n            if (length > (end-start+1)) {\n                break;\n            }\n\n            int[] count = new int[26];\n            int l = start;\n            int r = l;\n            HashSet<Integer> errors = new HashSet<>();\n\n            while (r <= end) {\n                int c = word.charAt(r)-\'a\';\n                count[c]++;\n                if (count[c] == k) {\n                    errors.remove(c);                    \n                } else {\n                    errors.add(c);\n                }\n                r++;\n                int currL = r - l;\n                if (currL < length) {\n                    continue;\n                }\n                if (currL > length) {\n                    c = word.charAt(l)-\'a\';\n                    count[c]--; \n                    if (count[c] == k || count[c] == 0) {\n                        errors.remove(c);                    \n                    } else {\n                        errors.add(c);\n                    }\n                    l++;\n                }\n\n                if (errors.isEmpty()) {\n                    res++;\n                }\n            }\n        }\n        return res;\n    }\n}\n```
['Java']