[JavaScript] Sliding Window + Frequency Count. Beats 100%
Intuition\n1. check Function: Verifies if the frequency array has j characters each occurring exactly k times.\n2. func Function: For each possible length from 
# Intuition\n1. `check` Function: Verifies if the frequency array has j characters each occurring exactly k times.\n2. `func` Function: For each possible length from k to 26*k, uses a sliding window to check all substrings of that length. \n    - Initializes the frequency array and updates it as the window slides. \n    - Counts valid substrings meeting the condition.\n3. `countCompleteSubstrings` Function:\n    - Splits the word into parts where adjacent characters differ by more than 2.\n    - For each part, calls func to count valid substrings.\n    - Returns the total count.\n\n\n# Complexity\n- Time complexity: O(n * 26 * k), where n is the length of the word.\n- Space complexity: O(26) for the frequency array.\n\n# Code\n```\n/**\n * @param {string} word\n * @param {number} k\n * @return {number}\n */\nvar countCompleteSubstrings = function(word, k) {\n    let ans = 0;\n    let result = "";\n    const n = word.length;\n\n    for (let i = 0; i < n; i++) {\n        result += word[i];\n        if (i < n - 1 && Math.abs(word.charCodeAt(i) - word.charCodeAt(i + 1)) > 2) {\n            ans += func(result, k);\n            result = "";\n        }\n    }\n    ans += func(result, k);\n    return ans;\n};\n\n/**\n * Function to check if the frequency vector has `j` characters each occurring `k` times.\n * @param {number[]} freq - Frequency array.\n * @param {number} j - Number of unique characters.\n * @param {number} k - Exact occurrences of each character.\n * @returns {boolean} - Returns true if the condition is met, otherwise false.\n */\nconst check = (freq, j, k) => {\n    let count = 0;\n    for (let i = 0; i < freq.length; i++) {\n        if (freq[i] === 0) continue;\n        if (freq[i] !== k) return false;\n        count++;\n    }\n    return count <= j;\n};\n\n/**\n * Function to count valid substrings in a given part of the word.\n * @param {string} s - Substring of the word.\n * @param {number} k - Exact occurrences of each character.\n * @returns {number} - Number of valid complete substrings.\n */\nconst func = (s, k) => {\n    let count = 0;\n    const n = s.length;\n    for (let j = 1; j <= 26; j++) {\n        const len = k * j;\n        const freq = Array(26).fill(0);\n        if (len > n) break;\n\n        // Initialize the frequency array for the first window\n        for (let i = 0; i < len; i++) {\n            freq[s.charCodeAt(i) - 97]++;\n        }\n        if (check(freq, j, k)) count++;\n\n        // Sliding window to check all substrings of length `len`\n        for (let i = len; i < n; i++) {\n            freq[s.charCodeAt(i - len) - 97]--;\n            freq[s.charCodeAt(i) - 97]++;\n            if (check(freq, j, k)) count++;\n        }\n    }\n    return count;\n};\n```\n![Screenshot 2024-06-26 at 11.26.01\u202FPM.png](https://assets.leetcode.com/users/images/3fcd71b2-8538-49b7-b756-a13ed0cc9e48_1719469706.9117527.png)\n
['JavaScript']