diff --git a/2799. Count Complete Subarrays in an Array b/2799. Count Complete Subarrays in an Array new file mode 100644 index 0000000..b950a4d --- /dev/null +++ b/2799. Count Complete Subarrays in an Array @@ -0,0 +1,20 @@ +class Solution { +public: + int countCompleteSubarrays(vector& nums) { + unordered_map m, m1; + for(int ele : nums) m[ele]++; + int n = nums.size(); + int distinct = m.size(); // total distinct elements in nums + int cnt = 0; + + for(int i = 0; i < n; i++) { + for(int j = i; j < n; j++) { + m1[nums[j]]++; + if(m1.size() == distinct) cnt++; + } + m1.clear(); + } + + return cnt; + } +};