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

265 篇文章 1 订阅
86 篇文章 0 订阅
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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值