Special product array
python3
array
To find a product of elements of an array we need to create an empty variable and initialize it with 1 .In a loop to get each element from user we need to multiply each element to product and print the product.
Example: Given a list of integers nums, return a new list such that each element at index i of the new list is the product of all the numbers in the original list except the one at i.
CONSTRAINTS:2 ≤ n ≤ 100,000 where n is the length of nums
When we give test case as input nums = [1, 2, 3, 4, 5]
we get output as [120, 60, 40, 30, 24]
explanation: 120 = 2 * 3 * 4 * 5 , 60 = 1 * 3 * 4 * 5 ,40=4 * 5 * 1 * 2 , 30=1 * 2 * 3 * 5 ,24=1 * 2 * 3 * 4
Top comments (0)