Sliding Window
Intuition\nIn general this problem only solved in $O(n^2)$ time, where $n$ is the $word$ length, for example:\n$word$ = "abc", k = 1\n1) Compute the number of c
# Intuition\nIn general this problem only solved in $O(n^2)$ time, where $n$ is the $word$ length, for example:\n$word$ = "abc", k = 1\n1) Compute the number of complete substrings if we started search at the $i = 0$ index of the $word$, i.e. from the $a$\n1.a) "a"\n1.b) "ab"\n1.c) "abc"\n\n2) Then compute, if we started at $i = 1$, i.e. from the $b$\n2.a) "b"\n2.b) "bc"\n\n3) And the last, if we started at $i = 2$, i.e. from the $c$\n3.a) "c"\n\nBut this problem has constraint: $n <= 10^5$, so we need to find a solution which will compute in linear time $O(n)$ or closer.\n\nSince the $word$ consist of only lowercase alphabet\'s, so the $word$  maximum length of unique substring is $26 * k$. So using the previous approach and taking into account this observation, we can reduce computation time from $O(n^2)$ to $O(n)$\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSliding Window\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $O(n)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(n)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n    pub fn count_complete_substrings(word: String, k: i32) -> i32 {        \n        let k = k as usize;\n        let n = word.len();\n\n        let b = word.as_bytes();\n\n        let mut g = Vec::new();\n\n        let mut j = 0;\n\n        for i in 1..n {\n            if (b[i] > b[i - 1] && b[i] > b[i - 1] + 2) || \n                (b[i] < b[i - 1] && b[i] < b[i - 1] - 2) \n            {\n                if i - j >= k {\n                    g.push((j, i - 1));\n                }\n\n                j = i;\n            }\n        }\n\n        if n - j >= k {\n            g.push((j, n - 1));\n        }\n\n        let mut r = 0;\n\n        for t in g {         \n            for i in 1..=26 {\n                if t.1 >= t.0 + k*i - 1 {\n                    let mut j = t.0;\n                    let mut l = t.0;\n\n                    let mut v = vec![0; 26];\n\n                    let mut p = 0;\n                    let mut q = 0;\n\n                    while l <= t.1 {\n                        let x = (b[l] - b\'a\') as usize;\n\n                        if v[x] == k || (v[x] == 0 && p == i) {\n                            while j < l {\n                                let y = (b[j] - b\'a\') as usize;\n\n                                if v[y] == k {\n                                    q -= 1;\n                                }\n\n                                v[y] -= 1;\n\n                                if v[y] == 0 {\n                                    p -= 1;\n                                }\n\n                                j += 1;\n\n                                if (v[x] > 0 && v[x] < k) || (v[x] == 0 && p < i) {\n                                    break;\n                                }\n                            }\n                        }\n\n                        if v[x] == 0 {\n                            p += 1;\n                        }\n\n                        v[x] += 1;\n\n                        if v[x] == k {\n                            q += 1;\n                        }\n\n                        if p == i && p == q {\n                            r += 1;\n                        }\n\n                        l += 1;\n                    }\n                }\n            }\n        }\n\n        r     \n    }\n}\n```
['Rust']