TomoLink
CompaniesInfosysData Structures & AlgorithmsMaximum Strength of a Group
DSA
MediumArray

Maximum Strength of a Group

arraydynamic programmingbacktracking

Problem Statement

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 i _0 , i _1 , i _2 , ... , i _k is defined as nums[i _0 ] nums[i _1 ] nums[i _2 ] ... nums[i _k ​] .

Return the maximum strength of a group the teacher can create .

Examples

Example 1
Input: nums = [3,-1,-5,2,5,-9]
Output: 1350
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
Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.

Constraints

1 <= nums.length <= 13
-9 <= nums[i] <= 9
🤔
Medium
Difficulty
Topic Info
ModuleDSA
CategoryArray
Sub-topicDynamic Programming
Tags
arraydynamic programmingbacktrackinggreedybit manipulationsortingenumeration
Navigation
Maximum Strength of a Group [Medium] | Infosys Dsa | TomoLink