@Ross: This satisfies your constraints...
B[0] = 1;
for( i = 1 ; i < N ; ++i )
B[i] = B[i-1] * A[i-1];
int x = 1;
for( i = N-1 ; i > 0 ; --i )
{
x *= A[i];
B[i-1] *= x;
}
Dave
On Jun 26, 11:08 am, ross <[email protected]> wrote:
> Given an array A , of N integers ( In no particular order), fill up an
> auxilary array B such that B[i] contains the product of
> all elements in A other than A[i].
> Constraints:
> O(n) Time,
> Can this be done with O(1) space?
> Division is *not* allowed .
>
> eg: A 1 2 3 4 5
> B 120 60 40 30 24
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.