python3 100% 100%
use hash map. \n\n\nclass Solution:\n    def subarraysWithKDistinct(self, A: List[int], K: int) -> int:\n        n = len(A)\n        i = k = 0\n        ans = 0\
use hash map. \n\n```\nclass Solution:\n    def subarraysWithKDistinct(self, A: List[int], K: int) -> int:\n        n = len(A)\n        i = k = 0\n        ans = 0\n        mMap = {}\n        for j in range(n):\n            if A[j] not in mMap:\n                mMap[A[j]] = 1\n            else:\n                mMap[A[j]] += 1\n            if len(mMap) < K:\n                continue\n            elif len(mMap) > K:\n                del mMap[A[k]]\n                i = k = k+1\n            while mMap[A[k]] > 1:\n                mMap[A[k]] -= 1\n                k += 1\n            ans += k - i + 1\n        return ans\n```
[]