Javascript - Sliding Window
\n/**\n * @param {string} word\n * @param {number} k\n * @return {number}\n */\nvar countCompleteSubstrings = function (word, k) {\n  let ans = 0;\n  const n = 
```\n/**\n * @param {string} word\n * @param {number} k\n * @return {number}\n */\nvar countCompleteSubstrings = function (word, k) {\n  let ans = 0;\n  const n = word.length;\n  for (let uniqueChars = 1; uniqueChars <= 26; uniqueChars++) {\n    let count = new Array(26).fill(0);\n    let exact = 0;\n    let start = 0;\n    const windowLen = uniqueChars * k;\n    for (let end = 0; end < n; end++) {\n      // restart from scratch\n      const diff = Math.abs(word.charCodeAt(end) - word.charCodeAt(end - 1));\n      if (end >= 1 && diff > 2) {\n        count = count.map(() => 0);\n        exact = 0;\n        start = end;\n      }\n\n      const curr = word.charCodeAt(end) - 97;\n      count[curr]++;\n      if (count[curr] === k) exact++;\n      if (count[curr] === k + 1) exact--;\n\n      // shrink window\n      if (end - start + 1 > windowLen) {\n        const prev = word.charCodeAt(start) - 97;\n        count[prev]--;\n        if (count[prev] === k - 1) exact--;\n        if (count[prev] === k) exact++;\n        start++;\n      }\n\n      // record answer\n      if (end - start + 1 === windowLen && exact === uniqueChars) {\n        ans++;\n      }\n    }\n  }\n\n  return ans;\n};\n```
['Sliding Window', 'JavaScript']