Re: How to find the maximum sum of atleast L consecutive integers given a sequence of N integers.
- From: "Roger Willcocks" <roger@xxxxxxxx>
- Date: Mon, 20 Mar 2006 15:48:47 -0000
"vb@xxxxxxxxx" <vb.here@xxxxxxxxx> wrote in message
news:1142859607.458037.81030@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
How can we find the maximum sum of atleast L consecutive integers given
a sequence of N integers.
The brute force approach of forming all possible length sequences at
every index and finding their sum gives an O(N^2) solution which is not
desirable.
Can somebody tell me a better approach for this ?
It can be calculated in O(N). See Robert Bentley's 'Programming Pearls' book
for more details.
There's a copy of the relevant chapter at:
http://www.student.cs.uwaterloo.ca/~cs134/Resources/read/Articles/Bentley/AlgorithmDesignTechniques.pdf
but I'd recommend the whole book. Think a bit more about the problem before
peeking!
--
Roger
.
- References:
- Prev by Date: Re: How to find the maximum sum of atleast L consecutive integers given a sequence of N integers.
- Next by Date: Re: Software product activation solution
- Previous by thread: Re: How to find the maximum sum of atleast L consecutive integers given a sequence of N integers.
- Next by thread: Re: How to find the maximum sum of atleast L consecutive integers given a sequence of N integers.
- Index(es):