#2708

Maximum Strength of a Group

expert · 1165 · lc medium +32 · verified · 25.6% accepted · 384 likes · top 4%

Description

Given a 0-indexed integer array nums of student scores, select any non-empty subset; its strength is the product of the chosen values. Return the maximum achievable strength.

Example 1:

Input: nums = [3,-1,-5,2,5,-9]
Output: 1350
Explanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.

Example 2:

Input: nums = [-4,-5,-4]
Output: 20
Explanation: Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.

Code

1
2
3