← All problems

Best Time to Buy and Sell Stock

Easy arraysgreedy LeetCode ↗
Given prices where prices[i] is the day-i price, pick one day to buy and a later day to sell for maximum profit. Return 0 if no profit possible.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1)

Common pitfalls

  • Allowing sell before buy (wrong order)
  • Forgetting the no-profit -> 0 case

Your solution

Log in to save your code and track progress.