Haskell Max Profit
maxProfit :: [Int] -> Int
maxProfit a = snd (foldl step (head a, 0) a)
  where
    step (price, profit) v =
      let price' = min price v
      in  (price', max profit (v - price'))

This tracks the lowest buy price seen so far and updates the best profit as it scans the prices once.