class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if len(prices) <= 1: return 0
 
        l, r, max_profit = 0, 1, 0
        while l < r < len(prices):
            # Check if there's a profit
            if prices[l] < prices[r]:
                max_profit = max(prices[r] - prices[l], max_profit)
            else:
                l = r
            
            r += 1
            
        return max_profit

Complexity

Time:
Space: