2708. Maximum Strength of a Group Medium
1/**
2 * [2708] Maximum Strength of a Group
3 *
4 * You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i0, i1, i2, ... , ik is defined as nums[i0] * nums[i1] * nums[i2] * ... * nums[ik].
5 * Return the maximum strength of a group the teacher can create.
6 *
7 * <strong class="example">Example 1:
8 *
9 * Input: nums = [3,-1,-5,2,5,-9]
10 * Output: 1350
11 * 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.
12 *
13 * <strong class="example">Example 2:
14 *
15 * Input: nums = [-4,-5,-4]
16 * Output: 20
17 * Explanation: Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= nums.length <= 13
23 * -9 <= nums[i] <= 9
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/maximum-strength-of-a-group/
29// discuss: https://leetcode.com/problems/maximum-strength-of-a-group/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn max_strength(nums: Vec<i32>) -> i64 {
35
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_2708() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.