← All problems
Best Time to Buy and Sell Stock
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.
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.