Lisp Max Profit
(defun max-profit (a)
(let ((price (first a))
(profit 0))
(dolist (v a)
(setf price (min price v))
(setf profit (max profit (- v price))))
profit))
This tracks the lowest buy price seen so far and updates the best profit as it scans the prices once.