Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by tye (Sage)
on Aug 30, 2006 at 19:09 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://570455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-23 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found