Jyotirmoy Barman

121. Best Time to Buy and Sell Stock
EasyArrayDynamic Programming

Single Pass Greedy Approach (Tracking Minimum Price)

func maxProfit(prices []int) int { res, low := 0, prices[0] for _, price := range prices { if price < low { low = price } res = max(res, price - low) } return res }
  • Time Complexity: O(n)
  • Space Complexity: O(1)