Personal tools

Haskell Quiz/Maximum Sub-Array/Solution Jkramar

From HaskellWiki

< Haskell Quiz | Maximum Sub-Array
Revision as of 19:58, 19 November 2008 by Jkramar (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


maxSubArray xs = drop from$take to xs where
  sums = zip (scanl (+) 0 xs) [0..]
  diff ((a,ai),(b,bi)) = (a-b,(bi,ai))
  (from,to) = snd$maximum$map diff$zip sums$scanl1 min sums