#K79067. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
You are given an integer array A of size n. Your task is to compute a new array B such that for every index i,
\(B[i] = \prod_{\substack{0 \leq j < n \\ j \neq i}} A[j]\)
In other words, each element in B is the product of all the numbers in A except the one at index i. Note that if the input array is empty (n=0), you should output an empty result.
This problem tests your ability to work with arrays and perform efficient computations by avoiding division and handling edge cases such as zeros in the array.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer n, representing the number of elements in the array. (n ≥ 0)
- If n > 0, the second line contains n space-separated integers representing the elements of the array.
outputFormat
The output should be written to standard output (stdout) as a single line containing n space-separated integers. These integers represent the product of all other numbers for each index of the input array. If n = 0, output nothing.
## sample4
1 2 3 4
24 12 8 6