Question
Product of Array Except Self - 2
You are given an array of
For each index
You must solve this without using the division operator anywhere in your solution, and your solution must run in
Input
The first line contains a single integer KaTeX can only parse string typed expression — the size of the array.
The second line contains KaTeX can only parse string typed expression integers KaTeX can only parse string typed expression.
Output
Print KaTeX can only parse string typed expression integers separated by spaces — the product of all elements except KaTeX can only parse string typed expression, for each index KaTeX can only parse string typed expression in order.
Example
Example 1:
Input
For index 1 (value 1), the product of the rest is KaTeX can only parse string typed expression. For index 2 (value 2), it is KaTeX can only parse string typed expression, and so on.
Example 2:
Input
Since the array contains a KaTeX can only parse string typed expression, every product except the one excluding that zero itself becomes KaTeX can only parse string typed expression. Only the position of the zero itself yields a nonzero product, from multiplying all the other elements together.
Example 3:
Input
KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, KaTeX can only parse string typed expression.
Input
4
1 2 3 4Output24 12 8 6ExplanationFor index 1 (value 1), the product of the rest is KaTeX can only parse string typed expression. For index 2 (value 2), it is KaTeX can only parse string typed expression, and so on.
Example 2:
Input
5
-1 1 0 -3 3Output0 0 9 0 0ExplanationSince the array contains a KaTeX can only parse string typed expression, every product except the one excluding that zero itself becomes KaTeX can only parse string typed expression. Only the position of the zero itself yields a nonzero product, from multiplying all the other elements together.
Example 3:
Input
3
2 3 5Output15 10 6ExplanationKaTeX can only parse string typed expression, KaTeX can only parse string typed expression, KaTeX can only parse string typed expression.