💥💥 Beats 100% on runtime and memory [EXPLAINED]
IntuitionFind substrings of a specific length where every character appears exactly k times, and adjacent characters differ by at most 2 alphabetically. This me
# Intuition
Find substrings of a specific length where every character appears exactly k times, and adjacent characters differ by at most 2 alphabetically. This means we need to balance constraints on character frequency and adjacency simultaneously.

# Approach
Iterate through possible substring lengths (multiples of k), use a sliding window with a frequency array to track character counts, reset if adjacency constraints break, and count valid substrings when conditions are met.

# Complexity
- Time complexity:
O(26 × n) because we process the string up to 26 times (once per possible character count) and use a sliding window for efficient processing.

- Space complexity:
O(1) because the frequency array is fixed in size at 26 (one slot per lowercase letter).

# Code
```typescript []
function countCompleteSubstrings(word: string, k: number): number {
    const n = word.length;
    let result = 0;

    for (let x = 1; x <= 26; x++) {
        const length = x * k;
        if (length > n) break;

        const freq = new Array(26).fill(0);
        let countFreqK = 0, l = 0;

        for (let r = 0; r < n; r++) {
            if (r > 0 && Math.abs(word.charCodeAt(r - 1) - word.charCodeAt(r)) > 2) {
                freq.fill(0);
                countFreqK = 0;
                l = r;
            }

            const charIndex = word.charCodeAt(r) - 97;
            if (freq[charIndex] === k) countFreqK--;
            freq[charIndex]++;
            if (freq[charIndex] === k) countFreqK++;

            while (r - l + 1 > length) {
                const leftCharIndex = word.charCodeAt(l) - 97;
                if (freq[leftCharIndex] === k) countFreqK--;
                freq[leftCharIndex]--;
                if (freq[leftCharIndex] === k) countFreqK++;
                l++;
            }

            if (r - l + 1 === length && countFreqK === x) result++;
        }
    }

    return result;
}

```
['Array', 'Hash Table', 'Ordered Map', 'Sliding Window', 'Hash Function', 'TypeScript']