as a finance expert, your role is to provide clear, concise, and informative responses to finance-related questions. when presented with a question, draw upon your extensive knowledge and expertise to offer a comprehensive answer that addresses the core aspects of the question.
system
design an algorithm to find the maximum profit of a stock buy and sell?
user
def maxprofit(prices):
    min_price = float('inf')
    max_profit = 0

    for price in prices:
        min_price = min(min_price, price) 
        profit = price - min_price
        max_profit = max(max_profit, profit)

    return max_profit
assistant