Skip to content

Commit 6bd240d

Browse files
committed
1994. The Number of Good Subsets: RETRY
1 parent f6509f5 commit 6bd240d

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1502,3 +1502,4 @@ mod s1987_number_of_unique_good_subsequences;
15021502
mod s1991_find_the_middle_index_in_array;
15031503
mod s1992_find_all_groups_of_farmland;
15041504
mod s1993_operations_on_tree;
1505+
mod s1994_the_number_of_good_subsets;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* [1994] The Number of Good Subsets
3+
*
4+
* You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.
5+
*
6+
* For example, if nums = [1, 2, 3, 4]:
7+
*
8+
* [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.
9+
* [1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.
10+
*
11+
*
12+
*
13+
* Return the number of different good subsets in nums modulo 10^9 + 7.
14+
* A subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.
15+
*
16+
* Example 1:
17+
*
18+
* Input: nums = [1,2,3,4]
19+
* Output: 6
20+
* Explanation: The good subsets are:
21+
* - [1,2]: product is 2, which is the product of distinct prime 2.
22+
* - [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.
23+
* - [1,3]: product is 3, which is the product of distinct prime 3.
24+
* - [2]: product is 2, which is the product of distinct prime 2.
25+
* - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
26+
* - [3]: product is 3, which is the product of distinct prime 3.
27+
*
28+
* Example 2:
29+
*
30+
* Input: nums = [4,2,3,15]
31+
* Output: 5
32+
* Explanation: The good subsets are:
33+
* - [2]: product is 2, which is the product of distinct prime 2.
34+
* - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
35+
* - [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.
36+
* - [3]: product is 3, which is the product of distinct prime 3.
37+
* - [15]: product is 15, which is the product of distinct primes 3 and 5.
38+
*
39+
*
40+
* Constraints:
41+
*
42+
* 1 <= nums.length <= 10^5
43+
* 1 <= nums[i] <= 30
44+
*
45+
*/
46+
pub struct Solution {}
47+
48+
// problem: https://leetcode.com/problems/the-number-of-good-subsets/
49+
// discuss: https://leetcode.com/problems/the-number-of-good-subsets/discuss/?currentPage=1&orderBy=most_votes&query=
50+
51+
// submission codes start here
52+
53+
impl Solution {
54+
pub fn number_of_good_subsets(nums: Vec<i32>) -> i32 {
55+
0
56+
}
57+
}
58+
59+
// submission codes end
60+
61+
#[cfg(test)]
62+
mod tests {
63+
use super::*;
64+
65+
#[test]
66+
#[ignore]
67+
fn test_1994_example_1() {
68+
let nums = vec![1, 2, 3, 4];
69+
70+
let result = 6;
71+
72+
assert_eq!(Solution::number_of_good_subsets(nums), result);
73+
}
74+
75+
#[test]
76+
#[ignore]
77+
fn test_1994_example_2() {
78+
let nums = vec![4, 2, 3, 15];
79+
80+
let result = 5;
81+
82+
assert_eq!(Solution::number_of_good_subsets(nums), result);
83+
}
84+
}

0 commit comments

Comments
 (0)