From: James Koppel Date: 2007-07-17T07:19:03+09:00 Subject: [QUIZ][SOLUTION] Maximum Sub-Array (#131) --0-1908406116-1184624335=:60087 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Solution #1: Array is bound to arr sub_arrs = [] arr.each_index{|i| (i...arr.length).each{|i2| sub_arrs << arr[i..i2]}} p sub_arrs.sort_by{|arr| arr.inject(0){|s,n|s+n}}.last Solution #2: Array is bound to a p (b=(0...(l=a.size)).to_a).zip([b]*l).map{|(i,s)|s.map{|j|a[i,j]}}.sort_by{|a|a.map!{|a|[a.inject(0){|s,n|s+n},a]}.sort![-1][0]}[-1][-1][-1] --------------------------------- Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. --0-1908406116-1184624335=:60087--