Given a list of integers a, choose any subset S of its indices. Let sum(S) be the sum of the selected values. The subset is special if sum(S) ≥ a[j] for every unselected index j.
0 and product 1. It is special only if every value in a is at most 0.1,000,000,007, in the range 0 to 1,000,000,006.Each method receives the same input parameter a, the list of integers.
int countSpecialSubsets(List<Integer> a)
int sumOfSpecialSubsetSums(List<Integer> a)
int sumOfSpecialSubsetProducts(List<Integer> a)
1 ≤ a.size() ≤ 100-1,000 ≤ a[i] ≤ 1,000countSpecialSubsets(a = List.of(2, 3, 4))
Output: 5
sumOfSpecialSubsetSums(a = List.of(2, 3, 4))
Output: 31
sumOfSpecialSubsetProducts(a = List.of(2, 3, 4))
Output: 54
The special subsets contain values [4], [2, 3], [2, 4], [3, 4], and [2, 3, 4]. Their sums total 31, and their products total 54.
countSpecialSubsets(a = List.of(-3, 2))
Output: 2
sumOfSpecialSubsetSums(a = List.of(-3, 2))
Output: 1
sumOfSpecialSubsetProducts(a = List.of(-3, 2))
Output: 1000000003
The special subsets contain [2] and [-3, 2]. Their sums total 1. Their products total -4, whose nonnegative remainder is 1000000003.
countSpecialSubsets(a = List.of(0, 0))
Output: 4
sumOfSpecialSubsetSums(a = List.of(0, 0))
Output: 0
sumOfSpecialSubsetProducts(a = List.of(0, 0))
Output: 1
All four index subsets are special. Every sum is 0. Nonempty subsets have product 0, while the empty subset contributes product 1.