Friday, November 13, 2009

The Array Multiplication Problem

Given: an array A of size N. Find the output array B, also of size N such that B[i] is the product of all elements of A except A[i]. That is,

B[0] = A[1] * A[2] * ... * A[N]
B[1] = A[0] * A[2] * A[3] * ... * A[N]
...
B[N] = A[0] * A[1] * ... * A[N - 1]

You have to do this in O(n) and WITHOUT using the division operator. :D

Solution.

No comments:

Post a Comment