<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the score of students in an exam. The teacher would like to form one <strong>non-empty</strong> group of students with maximal <strong>strength</strong>, where the strength of a group of students of indices <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, <code>i<sub>2</sub></code>, ... , <code>i<sub>k</sub></code> is defined as <code>nums[i<sub>0</sub>] * nums[i<sub>1</sub>] * nums[i<sub>2</sub>] * ... * nums[i<sub>k</sub>​]</code>.</p>

<p>Return <em>the maximum strength of a group the teacher can create</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,-1,-5,2,5,-9]
<strong>Output:</strong> 1350
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [-4,-5,-4]
<strong>Output:</strong> 20
<strong>Explanation:</strong> Group the students at indices [0, 1] . Then, we&rsquo;ll have a resulting strength of 20. We cannot achieve greater strength.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 13</code></li>
	<li><code>-9 &lt;= nums[i] &lt;= 9</code></li>
</ul>

class Solution:
    def maxStrength(self, nums: List[int]) -> int:
        # Edge case: If the list has only one element, return that element.
        if len(nums) == 1:
            return nums[0]
        # Separate positive and negative numbers, ignore zeros.
        positives = [num for num in nums if num > 0]
        negatives = [num for num in nums if num < 0]
    
        # Count zeros and handle edge cases where there are no non-zero elements.
        zero_count = nums.count(0)

        # If there are no positive or negative numbers, and there are only zeros, return 0.
        if len(positives) == 0 and len(negatives) == 0:
            return 0

        # If there is exactly one negative and no positives, return the largest negative or 0 if there are zeros.
        if len(positives) == 0 and len(negatives) == 1:
            return max(negatives[0], 0) if zero_count > 0 else negatives[0]

        # Sort negatives to handle the case of an odd number of negatives.
        negatives.sort()

        # If there are an odd number of negative numbers, remove the smallest one (the least negative one).
        if len(negatives) % 2 != 0:
            negatives.pop()

        # Calculate the product of all positive and remaining negative numbers.
        product = 1
        for num in positives + negatives:
            product *= num

        return product


        
16600