Haskell Max Product Of Three
import Data.List (sort)
maxProductOfThree :: [Int] -> Int
maxProductOfThree a =
max (s !! (n - 1) * s !! (n - 2) * s !! (n - 3)) (s !! 0 * s !! 1 * s !! (n - 1))
where
s = sort a
n = length s
This checks the useful extremes, because the best product can come from either the three largest numbers or two negatives plus one large positive.