Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5604 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 799 |

@sriramgoparaju99 | 737 |

@Manikanta punnam | 629 |

@rdakka | 606 |

@prankursharma31 | 597 |

@praveenbgp6 | 546 |

@sanskar94511 | 531 |

@purohitmn02 | 529 |

@yashkaril4 | 517 |

@abhikarshgupta | 474 |

@rohitgarg2825 | 464 |

Complete Leaderboard |

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

**Example 1:**

**Input:
**N = 5
A[] = {10, 3, 5, 6, 2}
**Output:
**180 600 360 300 900**
Explanation: **
For i=0, P[i] = 3*5*6*2 = 180.
For i=1, P[i] = 10*5*6*2 = 600.
For i=2, P[i] = 10*3*6*2 = 360.
For i=3, P[i] = 10*3*5*2 = 300.
For i=4, P[i] = 10*3*5*6 = 900.

**Example 2:**

**Input:
**N = 2
A[] = {12,0}
**Output:
**0 12

**Your Task:**

You do not have to read input. Your task is to complete the function **productExceptSelf() **that takes array A[] and N as input parameters and returns a list of N integers denoting the product array P. If the array has only one element the returned list should should contains one value i.e {1}

**Note: **Try to solve this problem without using the division operation.

**Expected Time Complexity: **O(N)

**Expected Auxiliary Space: **O(N)

**Constraints:**

1 <= N <= 1000

0 <= A_{i} <= 200

Array may contain duplicates.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Product array puzzle

...