DEV Community

loading...

Get an O(N) algorithm to find a product of a collection of numbers with a strange constraint

davidkou profile image XinyuStudio ・1 min read

This is a question when I participated a recent interview, I think it interesting. Let's say int n=10;

Input : An array int a[10];

Output: An array float b[10];

Requirement:

b[0]= a[1]*a[2]*...a[9];  //  product of all numbers in a, other than a[0]; 
b[1]= a[0]*a[2]*...a[9];  //  product of all numbers in

Discussion (0)

pic
Editor guide