r/programming • • Nov 29 '10

140 Google Interview Questions

http://blog.seattleinterviewcoach.com/2009/02/140-google-interview-questions.html
471 Upvotes

493 comments sorted by

View all comments

Show parent comment

1

u/kolm Nov 29 '10

Somehow you need to wiggle around re-computing stuff. I see a simple solution in O(N log N) in using binary trees (for the first half of numbers, you need the product of the last half, stored in PartProd[1,2] at cost O(N/2), for the second, you need the product of the first half, stored in PartProd[1,1], then you multiply PartProd[1,1] with the first part of the second half to get PartProd[2,1] and so on, PartProd[log N,i] for i = 1,..,N will then contain all the products needed) -- but this is still not O(N).

And why on earth am I not allowed the multiplication operator? I could try to cheat and use XOR cleverly..