4 ms·
iterate repeatedly over the sequence in question Does that ever seem like a good idea? The description suggests it may be a long list. That should give you a
by bsaunder 17y ago
iterate repeatedly over the sequence in question
Does that ever seem like a good idea? The description suggests it may be a long list. That should give you a hint that you don't need to do this to solve the problem.
- Estragon 17y agoI'm pretty sure you have to iterate over it at least twice. I guess the specification is implicit in that.
- anc2020 17y agoThe best case possible is to iterate the list once - you sum the list from left to right holding cumulative answers and if the final sum is zero, that index is a valid answer. The worst case of the best algorithm is to iterate twice - firstly as above, and then again in the opposite direction, comparing values from the first iteration.