Compass Interview Question: Given an input array of integ... | Glassdoor

Interview Question

Software Engineer Interview New York, NY

Given an input array of integers, return an array of the

  same size such that that ith element in the output array is the product of every element in the input array other than the ith element of the input array. Restriction: do not use division in your algorithm. This should be done in O(n) time complexity.
Answer

Interview Answer

2 Answers

0

Generate two additional arrays, one of which is the product of all numbers to the left of the ith element in the input array, and the other the product of all numbers to the right of the element in the input array. The value of the ith element of the output array is then the value of ith element of the first additional array multiplied by the value of the ith element of the second additional array. (Keep track of index positions carefully.)

Interview Candidate on Jan 30, 2016
0

Something like this:

http://codepad.org/KWpp387O

Adam on Feb 4, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.