var numberOfSubstrings = function (s, k) { let ans = 0; const n = s.length; let book = newArray(26).fill(0); for (let i = j = 0; j < n; j++) { let code_j = s[j].charCodeAt(0) - 97; book[code_j]++; if (book[code_j] >= k) ans += n - j; while (i < j && book[code_j] >= k) { let code = s[i].charCodeAt(0) - 97; book[code]--; i++; if (book[code_j] >= k && i < j) ans += n - j; } } return ans; };