Lisp Max Product Of Three
(defun max-product-of-three (a)
(let* ((sorted (sort (copy-list a) #'<))
(vec (coerce sorted 'vector))
(c (length vec)))
(max (* (aref vec (- c 1)) (aref vec (- c 2)) (aref vec (- c 3)))
(* (aref vec 0) (aref vec 1) (aref vec (- c 1))))))
This checks the useful extremes, because the best product can come from either the three largest numbers or two negatives plus one large positive.