#C12394. Product Except Self
Product Except Self
Product Except Self
Given an array of integers, compute an output array such that each element at index \(i\) is the product of all the numbers in the array except the one at \(i\). The goal is to solve the problem in \(O(n)\) time without using division.
If the list is empty, the output should be empty. In the case of a single element, output \(1\), since there are no other numbers to multiply.
Example: For input [1, 2, 3, 4], the expected output is [24, 12, 8, 6].
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line 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 to standard output (stdout) containing \(n\) space-separated integers. Each integer is the product of all other elements in the input array except the one at that position. If the array is empty (i.e., \(n = 0\)), output an empty line.
## sample4
1 2 3 4
24 12 8 6