Mindbending Product

Difficulty: EASY
Avg. time to solve
20 min
Success Rate

Problem Statement
Suggest Edit

You are given an array ‘ARR’ of size N, you have to construct a Product Array ‘P’ of the same size such that P[i] is equal to the product of all the elements of ARR except ARR[i]. The constraint is that you are not allowed to use the division operator.

Input format:
The first line contains an Integer 't' which denotes the number of test cases/queries to be run. 
Then the test cases follow. 

The first line of input for each test case/query contains an integer N representing the size of the array.
The second line of input for each test case/query contains N space-separated integers representing the elements of the array.
Output Format:
For each test case, print the product array P.

Output for every test case will be printed in a separate line.
1. You do not need to print anything, it has already been taken care of. Just implement the function.
2. The value of P[i] will fit into a 64-bit data type.
1 <= t <= 50
1 <= N <= 10
1 <= ARR [i] <= 20

 Time Limit: 1 sec
Sample Input 1:
10 3 5 6 2
12 20
Sample Output 1:
180 600 360 300 900
20 12
Test Case 1: 
For the product array P,
At i=0 we have 3*5*6*2 = 180.
At i=1 we have 10*5*6*2 = 600. 
At i=2 we have 10*3*6*2 = 360. 
At i=3 we have 10*3*5*2 = 300. 
At i=4 we have 10*3*5*6 = 900
So, the P array is 180 600 360 300 900

Test Case 2: 
For the product array P, 
At i=0, we have 20. 
At i=1, we have 12.
So, the P array is 20 12. 
Want to solve this problem? Login now to get access to solve the problems