[C++ / Go] 8 lines sliding window w/ multiple sizes O(N)
c++\nint countCompleteSubstrings(string word, int k) {\n    int res = 0;\n    for (int cSize = 1; cSize <= 26; ++cSize) {\n        vector<int> seen(128, k);\n  
```c++\nint countCompleteSubstrings(string word, int k) {\n    int res = 0;\n    for (int cSize = 1; cSize <= 26; ++cSize) {\n        vector<int> seen(128, k);\n        for (int wSize = cSize * k, n = cSize, i = 0, j = 0; j < word.size(); ++j) {\n            if (j && abs(word[j] - word[j - 1]) > 2) while (i < j) n += !seen[word[i++]]++;\n            if (j - i == wSize) n += !seen[word[i++]]++;\n            res += !(n -= !--seen[word[j]]);\n        }\n    }\n    return res;\n}\n```\n\n```go\nfunc countCompleteSubstrings(word string, k int) int {\n\tres := 0\n\tfor cSize := 1; cSize <= 26; cSize++ {\n\t\tvar (\n\t\t\tseen    [128]int\n\t\t\twSize   = cSize * k\n\t\t\tn, i, j int\n\t\t\texpand  = func() {\n\t\t\t\tseen[word[j]]++\n\t\t\t\tif seen[word[j]] == k {\n\t\t\t\t\tn++\n\t\t\t\t}\n\t\t\t\tj++\n\t\t\t}\n\t\t\tmove = func() {\n\t\t\t\tif seen[word[i]] == k {\n\t\t\t\t\tn--\n\t\t\t\t}\n\t\t\t\tseen[word[i]]--\n\t\t\t\ti++\n\t\t\t}\n\t\t\tdiscard = func() {\n\t\t\t\tfor i < j {\n\t\t\t\t\tmove()\n\t\t\t\t}\n\t\t\t}\n\t\t)\n\t\tfor j < len(word) {\n\t\t\tif j > 0 && math.Abs(float64(word[j])-float64(word[j-1])) > 2 {\n\t\t\t\tdiscard()\n\t\t\t} else if j-i >= wSize {\n\t\t\t\tmove()\n\t\t\t}\n\t\t\texpand()\n\t\t\tif n == cSize {\n\t\t\t\tres++\n\t\t\t}\n\t\t}\n\t}\n\treturn res\n}\n```
[]