Haskell Quiz/Maximum Sub-Array/Solution Jkramar
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
maxSubArray :: (Num a, Ord a) => [a] -> [a]
maxSubArray xs = drop from$take to xs where
sumswithpos = zip (scanl (+) 0 xs) [0..]
diff ((a,ai),(b,bi)) = (a-b,(bi,ai))
(from,to) = snd$maximum$map diff$zip sumswithpos$scanl1 min sumswithpos