Hacker News new | ask | show | jobs
by bloaf 3174 days ago
Am I stupid or do both of the solutions to the problem

"Replace each element of array with product of every other element without using / operator"

use the / operator?

My solution would involve summing the log() of the values in the array.

1 comments

There was just a post on HN to a site that went over this exact problem. Essentially, you do two linear scans to calculate the product of every number before an index, and to calculate the product of every number after an index. Then, for each index, the answer is just multiplying those two numbers you found for that index.