![]() |
VOOZH | about |
Given an array a, we need to find the maximum product possible with the subset of elements present in the array.
Input: a[] = [-1, -1, -2, 4, 3 ]
Output: 24
Explanation : Maximum product will be ( -2 * -1 * 4 * 3 ) = 24Input: a[] = [-1, 0]
Output: 0
Explanation: 0(single element) is maximum product possible
Table of Content
The idea is to recursively generate every possible non-empty subsequence of the array. For each element, there are two choices: either include it in the current subsequence or exclude it. While exploring all possible combinations, the product of the selected elements is maintained. Whenever the end of the array is reached, the product of the current non-empty subsequence is compared with the maximum product found so far.
024
The idea is to count the occurrence of positive and negative elements.
24