logo CodeStepByStep logo


Language/Type: C++ algorithms interview STL
Related Links:

Write a function named productOfOthers that accepts a reference to a vector of integers a as its parameter and returns a new vector where each element at index i stores the product of all elements in a excluding a[i]. For example, if the vector a stores {1, 4, 3, 4, 2}, the call of productOfOthers(a) should return {96, 24, 32, 24, 48}.

You may assume that the product of all elements in the vector is within the domain of integers (type int).

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.