Product of Array Except Self

Practice this coding question on Coding Gurukul.

Problem statement

Each machine contributes a calibration factor. For every machine, compute the combined product of all the other factors, leaving out its own. Zero and negative factors are allowed. Do not use division; target linear time.

Input format

First line: n. Second line: n space-separated integers.

Output format

Print n products in input order.

Constraints

2 <= n <= 100000; -10 <= factors <= 10; every prefix, suffix, and requested product fits a signed 64-bit integer.

Sample input

4
2 3 4 5

Sample output

60 40 30 24

Sign in to run or submit a solution in C++, Java or Python.