Erlang Max Slice Sum
-module(max_slice_sum).
-export([max_slice_sum/1]).
max_slice_sum([H | T]) ->
{_, Max} = lists:foldl(fun(V, {Tmp, MaxV}) ->
Tmp1 = max(Tmp + V, V),
{Tmp1, max(MaxV, Tmp1)}
end, {H, H}, T),
Max.
This is a Kadane-style scan: keep the best running sum and the best overall sum while moving once through the array.