#K41252. Product of Array Except Self

    ID: 26824 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of integers, compute a new array where each element at index \(i\) is the product of all the numbers in the original array except the element at \(i\). The challenge is to accomplish this without using division. Your solution should correctly handle cases with zeros, negative numbers, and even an empty array.

Note: When the input array is empty, the output should also be an empty array.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer (n), representing the number of elements in the array. The second line contains (n) space-separated integers. If (n = 0), the second line will be empty.

outputFormat

Output a single line to standard output (stdout) containing the transformed array as space-separated integers. For an empty input array, output nothing.## sample

4
1 2 3 4
24 12 8 6