Challenge 4: Array of Products of all Elements
In this challenge, you are given an array. Return an array where each index stores the product of all numbers in the array except the number at the index itself.
We'll cover the following
Problem statement
Implement a function findProduct(int arr[], int size)
, which takes an array arr
and its size
as an input, and returns an array so that each index has a product of all the numbers present in the array except the number stored at that index.
size
should be equal to or greater than 2.
Input
An array of integers and its size is given.
Output
The output is an array such that each index has a product of all the numbers in the array except the number stored at that index.
Sample input
arr = [1,2,3,4]
Sample output
arr = [24,12,8,6]
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.