Best Time to Buy and Sell Stock (I).
Asked in the Coding round stage.
Given an array prices, where prices[i] is the stock price on day i, choose exactly one day to buy and a later day to sell. Return the maximum possible profit. Return 0 if no profitable transaction exists.
Function: def max_profit(prices):
Input: A non-empty list of integers. Output: An integer representing the maximum profit.
Example 1: prices = [7, 1, 5, 3, 6, 4] returns 5, by buying at 1 and selling at 6.
Example 2: prices = [7, 6, 4, 3, 1] returns 0, because prices continually decrease.
Constraints: 1 <= len(prices) <= 1000; 0 <= prices[i] <= 10^5.
def max_profit(prices):