Given an array of prices, find the maximum profit possible.
Assume you may buy once and sell once, and the sale must occur after the purchase. Implement max_profit(prices), which accepts a list of nonnegative integers and returns the maximum profit as an integer, or 0 when no profitable transaction exists.
def max_profit(prices):