2799. Count Complete Subarrays in an Array Medium

@problem@discussion
#Array#Hash Table#Sliding Window



1/**
2 * [2799] Count Complete Subarrays in an Array
3 *
4 * You are given an array nums consisting of positive integers.
5 * We call a subarray of an array complete if the following condition is satisfied:
6 * 
7 * 	The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.
8 * 
9 * Return the number of complete subarrays.
10 * A subarray is a contiguous non-empty part of an array.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: nums = [1,3,1,2,2]
15 * Output: 4
16 * Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: nums = [5,5,5,5]
21 * Output: 10
22 * Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= nums.length <= 1000
28 * 	1 <= nums[i] <= 2000
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/count-complete-subarrays-in-an-array/
34// discuss: https://leetcode.com/problems/count-complete-subarrays-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn count_complete_subarrays(nums: Vec<i32>) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_2799() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.