#K88787. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an integer array A of length n (which may contain positive, negative, or zero values), compute an output array B such that for every index i,
$$ B_i = \prod_{\substack{j=0 \\ j \neq i}}^{n-1} A_j $$
This means that every element B[i] is equal to the product of all elements in A except the one at index i. You are required to implement the solution for multiple test cases.
Note: It is guaranteed that the product of elements (except self) will fit into the range of a 64-bit integer.
inputFormat
The input consists of multiple test cases. The first line contains an integer T, representing the number of test cases.
Each of the next T lines describes a test case. Each test case starts with an integer n, the size of the array, followed by n space-separated integers representing the array A.
Example:
2 4 1 2 3 4 3 -1 1 0
outputFormat
For each test case, output a single line containing the resulting array B with n space-separated integers. The output for each test case should be on a new line.
Example:
24 12 8 6 0 0 -1## sample
2
4 1 2 3 4
3 -1 1 0
24 12 8 6
0 0 -1
</p>