Easy to understand✅||Two pointer Approach||With Time & Space complexity
Complexity\n- Time complexity:\nO(2N)\nfor very much worst case that is not for all general cases, O(22N)\n\n- Space complexity:\n2O(N)\n\n# Code\n\n#include<bi
# Complexity\n- Time complexity:\nO(2N)\nfor very much worst case that is not for all general cases, O(2*2N)\n\n- Space complexity:\n2*O(N)\n\n# Code\n```\n#include<bits/stdc++.h>\n\nclass Solution {\npublic:\n    int helpme(vector<int>&nums, int goal){\n        if(goal<0) return 0;\n        int n=nums.size();\n        int l=0,r=0;\n        int cnt=0;\n        unordered_map<int,int> mp;\n        while(r<n){\n            mp[nums[r]]++;\n            while(mp.size()>goal){\n                mp[nums[l]]--;\n                if(mp[nums[l]]==0){\n                    mp.erase(nums[l]);\n                }\n                l++;\n            }\n            cnt+=(r-l+1);\n            r++;\n        }\n        return cnt;\n    }\n\n    int subarraysWithKDistinct(vector<int>& nums, int k) {\n        return helpme(nums,k) - helpme(nums,k-1);\n    }\n};\n```\n**PLEASE UPVOTE \u2B06**
['C++']