Given an array of transaction values, write an algorithm to find the maximum profit possible from buying and selling a stock. Implement def max_profit(prices):, where prices[i] is the stock value on day i; return the maximum profit from one buy followed by one later sell, or 0 if no profit is possible. For example, [7, 1, 5, 3, 6, 4] returns 5, while [7, 6, 4, 3, 1] returns 0; use 1 <= len(prices) <= 10^5.
def max_profit(prices):