您的位置:首页 > 其它

CareerCup Fill the array with product of all numbers except the number in that cell

2014-03-02 19:44 453 查看
Given N integer array, I want to fill the array with product of all numbers except the number in that cell.

What is the complexity ? Do not worry about 0's or negative numbers in the array.

[Interviewer was more interested in how the multiplication/division gets effected as number of bits required to represent the intermediate
products increases.]

---------------------------------------------------------------------------------------------

1. First pass calculate the product
P of all the numbers in array A

2. Second pass recreate the array A[i] = P / A[i]

As the interviewer has indicated the product can be very big, if the numbers in the array are big and/or the array length is big. Some languages support BigInteger operations,
like Python and I think Java also has BigInteger class. If using the programming language provided implementation is not an option, then you'll need to implement your own "BigInteger" class. You need to only implement the constructor, which will take the number
and convert it to string and then two methods for multiplication and division. C++ version will probably will overload the multiplication(*) and division(/) operators.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: