From b29db496d5301ddbdede5964122b7ee043843b52 Mon Sep 17 00:00:00 2001 From: chayan das Date: Thu, 24 Apr 2025 22:40:33 +0530 Subject: [PATCH] Create 2799. Count Complete Subarrays in an Array --- 2799. Count Complete Subarrays in an Array | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2799. Count Complete Subarrays in an Array 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; + } +};