2 ms·
I'm pretty sure you have to iterate over it at least twice. I guess the specification is implicit in that.
by Estragon 17y ago
I'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.