Interview Q: given an array of numbers, return array of products of all other numbers (no division)
Posted
by polygenelubricants
on Stack Overflow
See other posts from Stack Overflow
or by polygenelubricants
Published on 2010-04-21T05:29:08Z
Indexed on
2010/04/21
5:33 UTC
Read the original article
Hit count: 139
I was asked this question in a job interview, and I'd like to know how others would solve it. I'm most comfortable with Java, but solutions in other languages are welcome.
Given an array of numbers,
nums
, return an array of numbersproducts
, whereproducts[i]
is the product of allnums[j], j != i
.Input : [1, 2, 3, 4, 5] Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)] = [120, 60, 40, 30, 24]
You must do this in
O(N)
without using division.
© Stack Overflow or respective owner