laziness, impatience, and hubris | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi Every One,
I have improved my algorithm going from back to forward, but this time it also goes from left to right. You keep a current max, and current sum 3 2 8 9 -25 5 8 4 4 -3 5 3 -10 current sum 3 5 13 22 0 5 13 17 21 18 23 26 16 current max 3 5 13 22 22 22 22 22 22 22 23 26 26 When I reach -25. I update current sum and it is negtiave, so I start the current sum from here again from scratch. This method can even accept infinite numbers coming from an outside source, so it is on the fly algorithm which uses greedy methods Ilteris Murat Derici & David Matula In reply to Re: Largest Sum of Consecutive Integers
by Anonymous Monk
|
|