def get_max_profit(stock_prices):
    """
    Time Complexity: O(n)
    Space Complexity: O(1)

    n: number of stocks (length of the list)
    """
    if len(stock_prices) < 2:
        raise ValueError('Getting a profit requires at least 2 prices')

    min_price = stock_prices[0]
    max_profit = stock_prices[1] - stock_prices[0]

    for current_price in stock_prices[1:]:
        potential_profit = current_price - min_price
        min_price = min(min_price, current_price)
        max_profit = max(max_profit, potential_profit)

    return max_profit