You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
193 B
Ruby

def maximum_subsequence(arr)
max_so_far = 0
max_total = 0
arr.each do |el|
max_so_far = [max_so_far + el, 0].max
max_total = [max_total, max_so_far].max
end
max_total
end