Problem · Array
Product of Subset Maxima
Learn this problemProblem statement
Given an array values of positive integers, consider every non-empty subset of array indices. The value of a subset is the maximum array value selected by that subset.
Return the product of the values of all non-empty subsets, modulo 10^9 + 7.
Two equal values at different indices are still distinct selectable elements.
Function
productOfSubsetMaxima(values: int[]) → intExamples
Example 1
values = [1,2,3]return = 324The seven non-empty subsets have maxima 1, 2, 3, 2, 3, 3, 3. Their product is 324.
Example 2
values = [1,1,1,1]return = 1Every non-empty subset has maximum value 1.
Constraints
values.length >= 1.- Every element of
valuesis positive.