Javascript Solution, sliding window
Having as a guide the solutions from here: [Java/C++/Python] Sliding Window\n\n/**\n * @param {number[]} A\n * @param {number} K\n * @return {number}\n */\nvar 
Having as a guide the solutions from here: [[Java/C++/Python] Sliding Window](https://leetcode.com/problems/subarrays-with-k-different-integers/discuss/523136/JavaC++Python-Sliding-Window)\n```\n/**\n * @param {number[]} A\n * @param {number} K\n * @return {number}\n */\nvar subarraysWithKDistinct = function(A, K) {\n    return (atMostK(A, K) - atMostK(A, K - 1));\n};\n\nfunction atMostK(A, K) {\n      let count = {};\n    let maxArr = 0, windowStart = 0;\n\n    for (let windowEnd = 0; windowEnd < A.length; windowEnd++) {\n        const rightInt = A[windowEnd];\n\n        if (!(rightInt in count)) {\n            count[rightInt] = 0;\n        }\n\n        if (count[rightInt] === 0) {\n            K -= 1;\n        }\n        count[rightInt] += 1;\n\n        while (K < 0) {\n            const leftInt = A[windowStart];\n            count[leftInt] -= 1;\n            if (count[leftInt] === 0) {\n                K += 1;\n            }\n            windowStart += 1;        }\n        maxArr += windowEnd - windowStart + 1;\n    }\n\n    return maxArr;\n}\n\n```
['Sliding Window', 'JavaScript']