Maximum Sub-Array (#131)

On 7/13/07, anansi [email protected] wrote:

is :slight_smile:

but why is [2, 5, -1, 3] sum= 9 the sub-array with the maximum sum?
wouldn’t be [2,5,3,1] sum=11 the right solution?

A sub-array is a contiguous list within the overall array.

For [a,b,c], the sub-arrays are

[a], [b], [c], [a,b], [b,c] and of course [a,b,c], but [a,c] is NOT a
sub-array because the elements are not contiguous within the overall
array.

I’m looking forward to tackling this quiz this evening, what a rocking
Friday night it will be! :slight_smile:

Matt

Humm. OK well fizbuzz could be done as a one liner…
a reasonably readable version of this one looks like 10 lines to me…

yea just tried to shorten it. My version of this one can only
condense down to 2 lines, and I don’t wanna spend the time to do more
on it, considering the whole, at work thing :slight_smile:

–Kyle

On Jul 13, 2007, at 10:56 AM, David C. wrote:

Does it matter?
I think either selection would be acceptable. I would probably favor
the shorter one, but I don’t think it matters.

James Edward G. II

On 7/13/07, Sammy L. [email protected] wrote:

solutions aren’t as obvious (unless you’ve seen it before)
Thank you I felt completely stupid in desperately searching for a
O(n*log n) solution…
Robert

On Jul 13, 2007, at 1:29 PM, Ari B. wrote:

Being a nub at life, liberty, and ruby, what is the best way to
search it? Would it be to go and sum up the elements in every
possible array (ie, [abc] => [a]. [b]. [c]. [ab]. [bc])? Because
that seems like it would get very CPU consuming with larger arrays.

Let’s have this discussion after the no-spoiler period, please.

James Edward G. II

Being a nub at life, liberty, and ruby, what is the best way to
search it? Would it be to go and sum up the elements in every
possible array (ie, [abc] => [a]. [b]. [c]. [ab]. [bc])? Because that
seems like it would get very CPU consuming with larger arrays.

aRi
--------------------------------------------|
If you’re not living on the edge,
then you’re just wasting space.

Am I missing something, or is this one of the easiest quizzes that’s
been put forward?

–Kyle

On 7/13/07, Kyle S. [email protected] wrote:

yea just tried to shorten it. My version of this one can only
condense down to 2 lines, and I don’t wanna spend the time to do more
on it, considering the whole, at work thing :slight_smile:

I’ve golfed mine down to a 108-char method body for an exhaustive
search…

On 7/13/07, David C. [email protected] wrote:

What are the criteria for selecting from multiple possibilities? For example:

[1,2,3,-7,6]

Or this:

[1,2,3,-6,6]

options

[1,2,3]
[1,2,3,-6,6]
[6]