Easy O(n) Python solution
def maxProfit(prices):\n        max_profit, min_price = 0, float('inf')\n        for price in prices:\n            min_price = min(min_price, price)\n          
    def maxProfit(prices):\n        max_profit, min_price = 0, float('inf')\n        for price in prices:\n            min_price = min(min_price, price)\n            profit = price - min_price\n            max_profit = max(max_profit, profit)\n        return max_profit
['Python']