Find-maximum-subarray
Introduction to Algorithm Chinese third edition P42 page exercise 4.1-5
Maximal sub-array algorithm for non-recursive linear time
。。。 But Haskell didn't loop. , my writing is also described in the book ....
However, this problem has a very good function of the advantages of writing this problem is too cool, elegant! completely into the pit
The most gas is the problem on the Codewars, test all over but because a tab does not allow the submit. Rarely do a 5kyu problem, next time in advance to see issue
Algorithm description
The algorithm uses the following idea to design a non-recursive, linear time complexity algorithm for maximal subarray problems. Starting from the left edge of the array, processing from left to right, records the maximum number of sub-arrays that have been processed so far. If the largest subarray of A[1...J] is known, the largest sub-array of the solution is expanded to a[1...j+1] based on the following properties: A[1...j+1] The largest sub-array of either A[1...J], or a sub-array ai...j+1. In the case of the largest subarray of known A[1...J], the shape such as a[i can be found in linear time. J+1] Maximum sub-array
Look at the code.
Maxsequence:: [int], int
maxsequence [] = 0
maxsequence all@ (x:xs) = max (maxsequence xs) (maximum $ SCA NL (+) 0 All)