Problem · Array

Product of Subset Maxima

Learn this problem
MediumArcesium logoArcesiumFULLTIMEOA

Problem 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[]) → int

Examples

Example 1

values = [1,2,3]return = 324

The 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 = 1

Every non-empty subset has maximum value 1.

Constraints

  • values.length >= 1.
  • Every element of values is positive.

More Arcesium problems

drafts saved locally
public int productOfSubsetMaxima(int[] values) {
  // Write your code here.
}
values[1,2,3]
expected324
checking account