Java Sliding Window
Time: O(26n)\n\nI have some explainations:\nhttps://www.youtube.com/watch?v=Ks94IrrO7eo\n\n\nclass Solution {\n    public int countCompleteSubstrings(String wor
Time: O(26n)\n\nI have some explainations:\nhttps://www.youtube.com/watch?v=Ks94IrrO7eo\n\n```\nclass Solution {\n    public int countCompleteSubstrings(String word, int k) {\n        char[] arr = word.toCharArray();\n        int n = arr.length, result = 0, last = 0;\n        for (int i = 1; i <= n; i++) {\n            if (i == n || Math.abs(arr[i] - arr[i - 1]) > 2) {\n                result += getCount(arr, k, last, i - 1);\n                last = i;\n            }\n        }\n        return result;        \n    }\n    private int getCount(char[] arr, int k, int start, int end) {\n        int result = 0;\n        for (int i = 1; i <= 26 && i * k <= end - start + 1; i++) {\n            int[] cnt = new int[26];\n            int good = 0;\n            for (int j = start; j <= end; j++) {\n                char cR = arr[j];\n                cnt[cR - \'a\']++;\n                if (cnt[cR - \'a\'] == k) {\n                    good++;\n                }\n                if (cnt[cR - \'a\'] == k + 1) {\n                    good--;\n                }\n                \n                if (j >= start + i * k) {\n                    char cL = arr[j - i * k];\n                    if (cnt[cL - \'a\'] == k) {\n                        good--;\n                    }\n                    if (cnt[cL - \'a\'] == k + 1) {\n                        good++;\n                    }\n                    cnt[cL - \'a\']--;\n                }\n                if (good == i) {\n                    result++;\n                } \n            }\n           \n        }\n        return result;\n        \n    }\n    \n}\n\n```
[]