Max and Min Products
Easy Accuracy: 19.8% Submissions: 1533 Points: 2

Given a set, we need to find maximum and minimum possible product among all subsets of the set.
Examples:

Input : arr[] = {4, -2, 5};
Output: Maximum product = 20 
        Minimum product = -40
Maximum product is obtained by multiplying
4 5
Minimum product is obtained by multiplying 
4, -2, 5

Input : arr[] = {-4, -2, 3, 7, 5, 0, 1};
Output: Maximum product = 840 
        Minimum product = -420
Maximum product is obtained by multiplying
-4, -2, 3, 7, 5
Minimum product is obtained by multiplying 
-4, 3, 7, 

 

Input:
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of array. The second line contains N space-separated denoting the elements of the array.
 
Output:
Print the maximum product followed by a space followed by minimum subset product.
 
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 20
-9 ≤ A[i] <= 9
 
Example:
Input
2
3
1 2 3
4
-1 -2 -3 -4

Output

6 1
24 -24

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.