Count Complete Subarrays in an Array
Medium
You receive an array nums consisting of positive integers.
We call a subarray of an array complete if the following condition is satisfied:
- The count of distinct elements in the subarray is equal to the count of distinct elements in the whole array.
Find and provide the count of complete subarrays.
A subarray is a contiguous non-empty part of an array.
Example 1
Input: nums = [1,3,1,2,2]
Output: 4
Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].
Example 2
Input: nums = [5,5,5,5]
Output: 10
Explanation: The array consists only of the integer 5, so any subarray is complete. The count of subarrays that we can choose is 10.
Constraints
1 <= nums.length <= 10001 <= nums[i] <= 2000
Did this problem appear in one of your interviews?
Responses stay private.
