<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>

<p>We call a subarray of an array <strong>complete</strong> if the following condition is satisfied:</p>

<ul>
	<li>The number of <strong>distinct</strong> elements in the subarray is equal to the number of distinct elements in the whole array.</li>
</ul>

<p>Return <em>the number of <strong>complete</strong> subarrays</em>.</p>

<p>A <strong>subarray</strong> is a contiguous non-empty part of an array.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,1,2,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [5,5,5,5]
<strong>Output:</strong> 10
<strong>Explanation:</strong> The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 2000</code></li>
</ul>

class Solution:
    def countCompleteSubarrays(self, nums: List[int]) -> int:

        if len(nums) == 1:
            return 1
        # init counter 
        org_set = set(nums)
        n = len(nums)

        # slide windows with ptr slow and fast
        # subarray is nums[slow:fast+1]
        slow = 0
        sub_counter = Counter([])
        sub_set = set()
        ans = 0
        uni_cnt = len(org_set)


        for fast in range(n):
            sub_counter[nums[fast]] += 1
            sub_set = set([key for key, val in sub_counter.items() if val > 0])
            while len(sub_set) == uni_cnt:
                sub_counter[nums[slow]] -= 1
                
                sub_set = set([key for key, val in sub_counter.items() if val > 0])
                slow+=1
            
            ans += slow

        return ans



        # for slow in range(n-uni_cnt+1):
        #     for fast in range(slow+uni_cnt-1, n):
        #         if len(set(nums[slow:fast+1])) == uni_cnt:
        #             ans += 1
        # return ans
                

        # for fast in range(slow, n):
        #     slow = 0
        #     print(sub_counter)
        #     sub_set = set([key for key, val in sub_counter.items() if val > 0])
        #     print(sub_set)
        #     while sub_set == org_set:
        #         ans+=1
        #         sub_counter[nums[slow]] -= 1
        #         slow+=1
        #         sub_set = set([key for key, val in sub_counter.items() if val > 0])

        return ans

333