C++ | Sliding Window simple code
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nIf substring uses X types of alphabets, the length is X * k.\neach substr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nIf substring uses X types of alphabets, the length is X * k.\neach substring can have 1 ~ 26 types of alphabets, so we need to check sustring of length 1 * K, 2 * K, ... , 26 * K.\nFor each length, we can count correct substrings using Sliding Window.\nSo the time complexity is O(N * 26).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int N, K;\n    bool f_chk(int cnt[26],  int over_cnt) {\n        if(over_cnt > 0) return false;\n        for (int k = 0; k < 26; ++k) {                \n            if(cnt[k] != 0 && cnt[k] != K) return false;                \n        }\n        return true;\n    }\n\n    int f_count(int len, string &s) {\n        len *= K;\n        if(len > N) return 0;\n        int L = 0, R = 0, k;\n        int over_cnt = 0, ret = 0;\n        int _cnt[26] = { 0 };\n        for (R = 0; R < len; ++R) {                        \n            ++_cnt[s[R] - \'a\'];\n            if(R > 0 && abs(s[R] - s[R-1]) > 2) ++over_cnt;         \n        }        \n        if(f_chk(_cnt, over_cnt)) ++ret;        \n\n        for (; R < N; ++R) {\n            ++_cnt[s[R] - \'a\'];\n            --_cnt[s[L] - \'a\'], ++L;\n            if(abs(s[R] - s[R-1]) > 2) ++over_cnt;\n            if(abs(s[L] - s[L-1]) > 2) --over_cnt;            \n            if(f_chk(_cnt, over_cnt)) ++ret;        \n        }\n\n        return ret;\n    }\n\n    int countCompleteSubstrings(string word, int k) {\n        N = word.size();\n        K = k;\n        int ans = 0;\n        for (int i = 1; i <= 26; ++i) {\n            ans += f_count(i, word);\n        }\n        return ans;\n    }\n};\n```
['C++']