Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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??

in reply to Re: Largest Sum of Consecutive Integers (ends)
in thread Largest Sum of Consecutive Integers

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        

  • Comment on Re^2: Largest Sum of Consecutive Integers (means)

Replies are listed 'Best First'.
Re^3: Largest Sum of Consecutive Integers (means)
by OverlordQ (Hermit) on Aug 30, 2006 at 23:17 UTC
    I just gotta figure out what the heck you just said ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://570455]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-07-20 03:40 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (424 votes). Check out past polls.