Best Time To Buy and Sell Stock
If our selling pointer is less than our buy one, update the buy, so it's the lowest sell price we've seen to maximize profit.
class Solution:
def maxProfit(self, prices: List[int]) -> int:
buy, sell = 0, 0
maxProfit = 0
while sell < len(prices):
if prices[sell] < prices[buy]:
buy, sell = sell, sell + 1
else:
maxProfit = max(maxProfit, prices[sell] - prices[buy])
sell += 1
return maxProfit