#C12493. Product Except Self
Product Except Self
Product Except Self
Given an integer array \(A\) of length \(n\), your task is to compute an output array \(B\) such that \(B[i]\) is equal to the product of all elements of \(A\) except \(A[i]\). The solution must be implemented without using division and with a time complexity of \(O(n)\). Note that if \(n = 1\), the output should be [1].
Example:
- For \(A = [1, 2, 3, 4]\), the output is \(B = [24, 12, 8, 6]\).
- For \(A = [0, 1, 2, 3]\), the output is \(B = [6, 0, 0, 0]\).
- For \(A = [-1, 1, -2, 2]\), the output is \(B = [-4, 4, -2, 2]\).
Note: The input will be read from standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line of input contains an integer \(n\), representing the number of elements in the array. The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing \(n\) space-separated integers which represent the resulting product array.
## sample4
1 2 3 4
24 12 8 6
</p>