3 ms·
Isn't sorting (smallest first) then summing another method, distinct from the ones given?
by rwmj 2y ago
Isn't sorting (smallest first) then summing another method, distinct from the ones given?
- anonymoushn 2y agoIf you're going to do something like this, it seems like the TFA's suggestion of bucketizing by exponent and having one accumulator per exponent is cheaper (it doesn't require you to sort "all the way") and more correct (e.g. the input of a billion 1s was already sorted, but naively computing the sum gave an incorrect result).