C++ Modified Sliding Window || Clean Code || Easy To Understand || Explained Approach!!
Intuition\nAt first, i was not able to solve this question. Then i move onto the hints. \n\nWe can have array of size K, 2K, 3K....because the characters need t
# Intuition\nAt first, i was not able to solve this question. Then i move onto the hints. \n\nWe can have array of size K, 2*K, 3*K....because the characters need to be present in exactly k times to be eligible for the substring to be complete. Example if there are 3 different characters in a substring it must have a length of 3*k and each character must be having frequency of k. At max we can have 26 different characters, and if each of the 26 characters are present in the substring then it can have maximum length of 26*k. \n\nhence, we can fix the window for each size like k, 2k, 3k.....26k.\n\nand then we can apply sliding window on these fixed size window by keeping the adjacent characters to be in range of 2 spots in alphabets as said by the first point in the question.\n\n# Complexity\n- Time complexity:\nO(26 * n * 26)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool chk(vector<int>&count, int k){\n        for(int i = 0; i<26; i++){\n            // cout<<i<<" "<<count[i]<<endl;\n            if(count[i]!=0 and count[i]!=k){\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    int func(int window, int k, string word){\n        if(window>word.size()){\n            return 0;\n        }\n\n        int ans = 0;\n        int i = 0, j = 0;\n        vector<int>count(26,0);\n\n        while(j<word.size()){\n            if(j-i+1<window){\n                if(j==0 or abs(word[j]-word[j-1])<=2){\n                    count[word[j]-\'a\']++;\n                }\n                else{\n                    i = j;\n                    count = vector<int>(26,0);\n                    count[word[j]-\'a\']++;\n                }\n            }\n\n            else{\n                if(j==0 or j == i or abs(word[j]-word[j-1])<=2){\n                    count[word[j]-\'a\']++;\n                    // cout<<i<<j<<endl;\n\n                    if(chk(count,k)){\n                        ans++;\n                    }\n\n                    count[word[i]-\'a\']--;\n                    i++;\n                }\n\n                else{\n                    // cout<<i<<j<<endl;\n                    i = j;\n                    count = vector<int>(26,0);\n                    count[word[j]-\'a\']++;\n                }\n            }\n\n            j++;\n        }\n\n        return ans;\n    }\n\n    int countCompleteSubstrings(string word, int k) {\n        int ans = 0;\n\n        for(int i = 1; i<=26; i++){\n            ans+=func(i*k,k,word);\n        }\n\n        return ans;\n    }\n};\n```
['C++']