Minimum product subset of an array
https://www.geeksforgeeks.org/minimum-product-subset-array/
Given an array a, we have to find minimum product possible with the subset of elements present in the array. The minimum product can be single element also.
Examples:
Input : a[] = { -1, -1, -2, 4, 3 }
Output : -24
Explanation : Minimum product will be ( -2 -1 -1 4 3 ) = -24
Input : a[] = { -1, 0 }
Output : -1
Explanation : -1(single element) is minimum product possible
Input : a[] = { 0, 0, 0 }
Output : 0
- 如果有偶数个负数且没有零,则结果为除最大负数之外的所有值的乘积。
- 如果有奇数个负数而没有零,那么结果就是所有乘积。
- 如果只有零和正,没有负,则结果为0。例外情况是,当没有负数且所有其他元素为正时,我们的结果应为第一个最小正数
1 |
|