The stupid question is the question not asked  
PerlMonks 
Re^2: Largest Sum of Consecutive Integers (means)by tye (Sage) 
on Aug 30, 2006 at 19:09 UTC ( #570455=note: print w/replies, xml )  Need Help?? 
A "fun" challenge would be to come up with a dataset where my above method won't work. I think such exist, but I don't see clearly how to construct one (probably a lot of alternating positive and negative numbers). Dealing with the sum of left and rightside endruns certainly makes the problem easier to think about. I think I've got a much simplertoimplement algorithm that will work on any set now. I'd construct the list of leftside endrun sums and the list of rightside endrun sums and track the "most negative so far" as you build it. Then you can just iterate one list and look up in the other list and select the maximum sum in O(N). If it weren't homework and/or I wasn't busy doing stuff that I get paid for, then I'd probably write up the code to do that. :)  tye
In Section
Seekers of Perl Wisdom

