P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 right-side end-runs certainly makes the problem easier to think about. I think I've got a much simpler-to-implement algorithm that will work on any set now. I'd construct the list of left-side end-run sums and the list of right-side end-run 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 reply to Re^2: Largest Sum of Consecutive Integers (means)
by tye
|
|