Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


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
Node Status?
node history
Node Type: note [id://570455]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2017-12-11 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (285 votes). Check out past polls.

    Notices?