#C12883. Product Except Self
Product Except Self
Product Except Self
Given an array of integers, compute a new array such that each element at index \(i\) is the product of all the numbers in the original array except the one at \(i\). For an empty array, the result should be an empty array.
Example: For the input array [1, 2, 3, 4], the expected output is [24, 12, 8, 6].
Mathematical formulation: For an array \(A\) of length \(n\), the result array \(R\) is defined as: \(R[i] = \prod_{\substack{0 \leq j < n \\ j \neq i}} A[j]\). This must be implemented without using division and in \(O(n)\) time.
Your task is to implement an efficient solution that computes the product array as described.
inputFormat
The first line contains an integer (n), representing the number of elements in the array. The second line contains (n) space-separated integers representing the array.
outputFormat
Print the resulting array where each element is the product of all the original array elements except the one at that index. The output should be a single line with (n) space-separated integers.## sample
4
1 2 3 4
24 12 8 6