Given an array **A** of size **N**, construct a Product Array **P** (of same size) such that** P** is equal to the product of all the elements of **A** except A[i].

**Input:**

The first line of input contains an integer **T** denoting the number of test cases. T testcases follow. Each testcase contains two lines of input. The first line is **N**. The second line contains **N** elements separated by spaces. It is guranteed that the product of all the elements of the array will not exceed 1e18.

**Output:**

For every test case, print the product array in a new line.

**Your Task:**

You do not have to read input. Your task is to complete **productExceptSelf() **function and returns the Product vector **P **that holds product except for self at each index.

**Constraints:**

1 <= T <= 100

1 <= N <= 1000

0 <= A_{i} <= 200

**Example:**

**Input:**

2

5

10 3 5 6 2

2

12 0

**Output:**

180 600 360 300 900

0 12

**Explanation:**

**Testcase1:** For the product array P, at i=0 we have 3*5*6*2. At i=1 10*5*6*2. At i=2 we have 10*3*6*2. At i=3 we have 10*3*5*2. At i=4 we have 10*3*5*6

So P is 180 600 360 300 900

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

murli01 | 343 |

decoder_101 | 274 |

john_wick | 204 |

singhalsaurav1997 | 196 |

Sulagna | 189 |

john_wick | 725 |

PiyushPandey4 | 717 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

decoder_101 | 512 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.