Java Sol || So Easy!
Code\n\n class Solution {\n     public int subarraysWithKDistinct(int[] nums, int K) {\n        int[] numFreq = new int[nums.length+1];\n        int distinct = 
# Code\n```\n class Solution {\n     public int subarraysWithKDistinct(int[] nums, int K) {\n        int[] numFreq = new int[nums.length+1];\n        int distinct = 0, start = 0, minEnd = 0, total = 0;\n        while (distinct == K || minEnd < nums.length) {\n            while (distinct < K && minEnd < nums.length) \n\t\t\t    if (numFreq[nums[minEnd++]]++ == 0) \n                distinct++;\n            int maxEnd = minEnd;\n            while (maxEnd < nums.length && numFreq[nums[maxEnd]] > 0)\n\t\t\t    maxEnd++;\n            while (distinct == K) {\n                if (numFreq[nums[start++]]-- == 1)\n                distinct--;\n                total += (maxEnd - minEnd + 1);\n            }\n        }\n        return total;\n    }\n }\n```
['Java']