Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 782 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

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

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.