Maximum Subarray Sum – Kadane’s Algorithm

Run Settings
LanguageRuby
Language Version
Run Command
def max_sub_arr(arr) max = 0 max_last = 0 arr.each do |i| max_last += i if max_last > max max = max_last end if max_last < 0 max_last = 0 end end return max end puts max_sub_arr([1,2,-4,-5,4,5,-1,-3,7,1,-2,-3,-5])
Editor Settings
Theme
Key bindings
Full width
Lines