2913. Subarrays Distinct Element Sum of Squares I Easy

@problem@discussion
#Array#Hash Table



1/**
2 * [2913] Subarrays Distinct Element Sum of Squares I
3 *
4 * You are given a 0-indexed integer array nums.
5 * The distinct count of a subarray of nums is defined as:
6 * 
7 * 	Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].
8 * 
9 * Return the sum of the squares of distinct counts of all subarrays of nums.
10 * A subarray is a contiguous non-empty sequence of elements within an array.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: nums = [1,2,1]
15 * Output: 15
16 * Explanation: Six possible subarrays are:
17 * [1]: 1 distinct value
18 * [2]: 1 distinct value
19 * [1]: 1 distinct value
20 * [1,2]: 2 distinct values
21 * [2,1]: 2 distinct values
22 * [1,2,1]: 2 distinct values
23 * The sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 + 2^2 + 2^2 + 2^2 = 15.
24 * 
25 * <strong class="example">Example 2:
26 * 
27 * Input: nums = [1,1]
28 * Output: 3
29 * Explanation: Three possible subarrays are:
30 * [1]: 1 distinct value
31 * [1]: 1 distinct value
32 * [1,1]: 1 distinct value
33 * The sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 = 3.
34 *  
35 * Constraints:
36 * 
37 * 	1 <= nums.length <= 100
38 * 	1 <= nums[i] <= 100
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/
44// discuss: https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn sum_counts(nums: Vec<i32>) -> i32 {
50        0
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_2913() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.