Brute force approach (TLE)....Tell this to the interviewer at first
TC: Approx O(n^2)\n\n public int subarraysWithKDistinct(int[] arr, int k) {\n        \n        // 55 / 55 test cases passed, but took too long.\n\t\t\n        i
TC: Approx O(n^2)\n```\n public int subarraysWithKDistinct(int[] arr, int k) {\n        \n        // 55 / 55 test cases passed, but took too long.\n\t\t\n        int cogs=0; //count of good subarrays\n        int count = 0, n = arr.length, si = 0, ei = 0;\n        int[] freq = new int[20000 + 1];\n        \n        \n        while (ei<n) {\n            if (ei<n && freq[arr[ei++]]++ == 0) count++;\n            \n            if(count==k) cogs++;\n            \n            if (count > k || ei==n) {\n                si++;\n                ei=si;\n                count = 0;\n                freq = new int[20000 + 1];\n            }\n            \n        }\n\n        return cogs;\n        \n    }\n```\n\nAnyone know other working solution than the atMost(k)-atMost(k-1) solution?....(well this was O(n))
[]