C++ | sliding window + hashmap
Approach\nFor each i,\n1. Use sliding window find the left boudery satisfies the second criteria.\n2. Record each letter\'s position and check the substring wit
# Approach\nFor each i,\n1. Use sliding window find the left boudery satisfies the second criteria.\n2. Record each letter\'s position and check the substring with length =  k, 2k, 3k... satisfy the first criteria.\n\n# Complexity\n- Time complexity:\n$$O(26 * n)$$\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int countCompleteSubstrings(string word, int k) {\n        int len = word.length();\n        vector<int> starts(len);\n        iota(starts.begin(), starts.end(), 0);\n        int s = 0;\n        for (int i = 1; i < len; ++i) {\n            if (abs(word[i] - word[i - 1]) <= 2) {\n                starts[i] = s;\n            } else {\n                s = i;\n            }\n        }\n        vector<vector<int>> pos(26);\n        for (int i = 0; i < len; ++i) {\n            pos[word[i] - \'a\'].push_back(i);\n        }\n        vector<int> vec(26, -1);\n        int result = 0;\n        for (int i = 0; i < len; ++i) {\n            vector<int> possiblePos;\n            vec[word[i] - \'a\']++;\n            for (int ch = 0; ch < 26; ++ch) {\n                if (vec[ch] >= (k - 1)) {\n                    possiblePos.push_back(pos[ch][vec[ch] - k + 1]);\n                }\n            }\n            sort(possiblePos.begin(), possiblePos.end(), greater<int>());\n            for (int j = 0; j < possiblePos.size(); ++j) {\n                if (possiblePos[j] < starts[i]) {\n                    break;\n                }\n                int cnt = j + 1;\n                if (i - possiblePos[j] + 1 == cnt * k) {\n                    ++result;\n                }\n            }\n        }\n        return result;\n    }\n};\n```
['C++']