Sliding Window, Multiple Times
Intuition\n Describe your first thoughts on how to solve this problem. \nSince each character occurs exactly k times in a complete substring, the substring can 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince each character occurs exactly k times in a complete substring, the substring can only have 1/2/.../26 types of characters. In other words, its length can be k/2k/.../26k.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor each possible substring size, apply the sliding window technique to find out all complete substrings. Remember two things:\nrestart the window when `s[i-1]` and `s[i]` has a gap larger than 2;\neach character should occur k times in the substring.\n\nFor example, `word = "ababbcxxyzyxfghgf"`. Restart window at the first `\'a\' \'x\'` and `\'f\'`.\n\nAnd we break the outer loop when times * k > word.size(), e.g. word = "abcdefx" k = 3, stop at times = 3.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    int slidingWindow(string& s, int t, int k) {\n        int n = s.size(), len = t * k, ans = 0;\n        unordered_map<char, int> freq;\n        for (int i = 0, start = 0; i < n; i++) {\n            if (i == 0 || abs(s[i - 1] - s[i]) > 2) {\n                freq.clear();\n                start = i;\n            }\n\n            freq[s[i]]++;\n            if (i - start + 1 >= len) {\n                if (freq.size() == t) {\n                    auto it = freq.begin();\n                    for (; it != freq.end(); it++) {\n                        if (it->second != k) {\n                            break;\n                        }\n                    }\n\n                    ans += it == freq.end();\n                }\n                \n                if (--freq[s[i - (len - 1)]] == 0) {\n                    freq.erase(s[i - (len - 1)]);\n                }\n            }\n        }\n\n        return ans;\n    }\npublic:\n    int countCompleteSubstrings(string word, int k) {\n        int n = word.size(), ans = 0;\n        for (int t = 1; t <= 26 && t * k <= n; t++) {\n            ans += slidingWindow(word, t, k);\n        }\n\n        return ans;\n    }\n};\n```
['C++']