2963. Count the Number of Good Partitions Hard

@problem@discussion
#Array#Hash Table#Math#Combinatorics



1/**
2 * [2963] Count the Number of Good Partitions
3 *
4 * You are given a 0-indexed array nums consisting of positive integers.
5 * A partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.
6 * Return the total number of good partitions of nums.
7 * Since the answer may be large, return it modulo 10^9 + 7.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: nums = [1,2,3,4]
12 * Output: 8
13 * Explanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).
14 * 
15 * <strong class="example">Example 2:
16 * 
17 * Input: nums = [1,1,1,1]
18 * Output: 1
19 * Explanation: The only possible good partition is: ([1,1,1,1]).
20 * 
21 * <strong class="example">Example 3:
22 * 
23 * Input: nums = [1,2,1,3]
24 * Output: 2
25 * Explanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= nums.length <= 10^5
31 * 	1 <= nums[i] <= 10^9
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/count-the-number-of-good-partitions/
37// discuss: https://leetcode.com/problems/count-the-number-of-good-partitions/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn number_of_good_partitions(nums: Vec<i32>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2963() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.