Find the maximum profit from buying and selling a stock given an array of prices.
Given prices, where prices[i] is the stock price on day i, return the maximum profit possible from buying once and selling once later. If no profitable transaction exists, return 0.
The function must accept a list of integers and return an integer. The sale must occur after the purchase.
def max_profit(prices):
def max_profit(prices):