You were asked to reason about stock prices throughout the day and compute the maximum possible profit from a single buy and sell without trivial brute force. How would you solve it?
Implement max_profit(prices). Given a list of daily prices, return the greatest profit from buying on one day and selling on a later day. Return 0 when no profitable transaction exists.
Input: prices, a list of integers. Output: an integer profit.
def max_profit(prices):