Sliding window in js, Beats 73.31% in runtime
Intuition\n Describe your first thoughts on how to solve this problem. \nsliding window\n\n# Approach\n Describe your approach to solving the problem. \nif we a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsliding window\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nif we are on our left and right pointers such that number of any char is equal to k, we need to add to our final count that substring and all left and right substrings, record that we have counted all substrings for the given left and right positions, so we dont double count same substrings. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nit is a constant time\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nconstant for keep a set, and a map\n\n![image.png](https://assets.leetcode.com/users/images/9da3b885-9f39-404f-9180-1e3bbcba31f0_1731071592.218727.png)\n\n\n# Code\n```javascript []\n/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n dababck; k=2\n map : {d: 0, a: 1, b: 2}\n */\nvar numberOfSubstrings = function(s, k) {\n    let cnt = 0;\n    const map = new Map();\n    let l = 0, r = 0;\n    const seen = new Set()\n    \n\n    while (r < s.length) {\n        map.set(s[r], (map.get(s[r])??0)+1);\n\n        while (map.get(s[r]) === k) {\n            if (!seen.has(`${l}->${r}`)) {\n                cnt += 1\n                cnt += s.length - r - 1;\n            }\n            seen.add(`${l}->${r}`)\n            map.set(s[l], map.get(s[l])-1)\n            l++;\n        }\n        r++;\n    }\n\n    return cnt;\n};\n```
['JavaScript']