Product of Array Except Self
Mediumjavapythonccppjavascript
For every position i, compute the product of all elements except A[i]. Do not use division. (Constraints are kept small so every product fits in a 64-bit integer.)
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print N space-separated integers, where the i-th value is the product of every element except the i-th.
Example 1
Input
4 1 2 3 4
Output
24 12 8 6
Explanation: For index 0 the product of the others is 2*3*4 = 24; the same idea applies to every index.
- 2 <= N <= 12
- -9 <= A[i] <= 9