#C14813. Product Except Self

    ID: 44504 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers, your task is to return an array where each element at index \(i\) is equal to the product of all the numbers in the original array except the one at index \(i\). You must solve this problem without using the division operator and with a linear time complexity of \(O(n)\).

In other words, for an input array \(nums\) of length \(n\), compute the array \(answer\) such that:

$$ answer[i] = \prod_{\substack{0 \leq j < n \\ j \neq i}} nums[j] $$

Consider edge cases such as arrays containing zeros, negative numbers, or even a single element.

inputFormat

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 of \(n\) space-separated integers, where the \(i\)-th integer is the product of all the elements in the input array except the element at index \(i\).

## sample
4
1 2 3 4
24 12 8 6