Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Mindbending Product
EASY
20 mins
19 upvotes
Arrays
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Arrays
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Mindbending Product

Contributed by
Dhruv Sharma
Easy
yellow-spark
0/40
Avg time to solve 20 mins
Success Rate 80 %
Share
19 upvotes

Problem Statement

You are given an array ‘ARR’ of size N. You have to construct a Product Array ‘P’ of the same size such that P[i] is equal to the product of all the elements of ARR except ARR[i]. The constraint is that you are not allowed to use the division operator.

For Example:

For an array {1, 2, 3, 4, 5}:
The required product array generated from the given array is {120, 60, 40, 30, 24 }

This can be generated in the following manner:

For generating 120 we have 2 * 3 * 4 * 5 i.e. the product of other array elements except 1.
For generating 60 we have 1 * 3 * 4 * 5  i.e. the product of other array elements except 2.
For generating 40 we have 1 * 2 * 4 * 5  i.e. the product of other array elements except 3.
For generating 30 we have 1 * 2 * 3 * 5  i.e. the product of other array elements except 4.
For generating 24 we have 1 * 2 * 3 * 4  i.e. the product of other array elements except 5.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
5
10 3 5 6 2
2
12 20
Sample Output 1:
180 600 360 300 900
20 12
Explanation:
Test Case 1: 
For the product array P,
At i=0 we have 3*5*6*2 = 180.
At i=1 we have 10*5*6*2 = 600. 
At i=2 we have 10*3*6*2 = 360. 
At i=3 we have 10*3*5*2 = 300. 
At i=4 we have 10*3*5*6 = 900
So, the P array is 180 600 360 300 900

Test Case 2: 
For the product array P, 
At i=0, we have 20. 
At i=1, we have 12.
So, the P array is 20 12. 
Reset Code
Full screen
Auto
copy-code
Console