On Fri, 13 Jul 2007 19:47:11 +0200, anansi wrote: > could someone explain this please? I really don't understand this quiz? > > Given an array of integers, find the sub-array with maximum sum. For > > example: > > > > array: [-1, 2, 5, -1, 3, -2, 1] maximum > > sub-array: [2, 5, -1, 3] > > I know what an array is :) I know what integers are :) I know what a sum > is :) > > 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? Because the subarrays in the quiz problem must be contiguous. The answer to your proposed version is ARRAY=[-1, 2, 5, -1, 3, -2, 1] ARRAY.select{|x| x>=0} --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/