VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-product-subset-array/

⇱ Minimum product subset of an array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum product subset of an array

Last Updated : 13 Jun, 2026

Given an integer array arr[], determine the minimum possible product that can be obtained by multiplying the elements of any non-empty subset of the array. 

Examples:

Input: arr[] = [1, 2, 3]
Output: 1
Explanation: The possible subset products are 1, 2, 3, 2, 3, 6, and 6. The minimum product is 1, obtained by selecting the subset [1].

Input: arr[] = [4, -2, 5]
Output: -40
Explanation: The minimum product is -40, obtained by selecting the subset [4, -2, 5].

[Naive Approach] Generate All Non-Empty Subsets - O(2 ^ n * n) Time O(1) Space

The idea is to generate all possible non-empty subsets of the array using bit masking. For each subset, calculate the product of its elements and keep track of the minimum product obtained. Finally, return the smallest product among all subsets.


Output
-40

Time Complexity: O(2 ^ n * n)
Auxiliary Space: O(1)

[Expected Approach] Mathematical Observation - O(n) Time O(1) Space

The idea is to use the properties of positive, negative, and zero elements. Compute the product of all non-zero elements and count the number of negative values. If the number of negatives is odd, the product of all non-zero elements gives the minimum product. If it is even, exclude the negative element with the smallest absolute value. Handle special cases involving only zeros or only positive numbers separately.

Let us understand with example:
Input: arr[] = [4, -2, 5]

  • Initialize neg = 0, zero = 0, prod = 1, mnNegAbs = INT_MAX, and mnPos = INT_MAX.
  • Process 4: prod = 4, mnPos = 4.
  • Process -2: prod = -8, neg = 1, mnNegAbs = 2.
  • Process 5: prod = -40, mnPos = 4.
  • Since the number of negative elements is odd (neg = 1), return prod = -40 as the minimum subset product.

Output
-40

Time Complexity: O(n)
Auxiliary Space: O(1)

Comment