#C7285. Product Except Self
Product Except Self
Product Except Self
You are given a list of integers. For each index (i), you must compute the product of all the integers in the list except the one at index (i). In other words, if the input list is (nums), then the output list (result) should satisfy: [ result[i] = \prod_{\substack{0 \leq j < n \ j \neq i}} nums[j] ]
Note: You are not allowed to use division and the solution should run in (O(n)) time. The list will have a length between 2 and (10^4), and each element (nums[i]) will be within the range ([-100, 100]).
Examples:
- For input
1 2 3 4
, the output should be24 12 8 6
. - For input
-1 2 -3 4
, the output should be-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.
- The second line contains \(n\) space-separated integers.
outputFormat
Print a single line to standard output (stdout) containing (n) space-separated integers where the (i)th integer is the product of all elements of the input list except the (i)th element.## sample
4
1 2 3 4
24 12 8 6