121. Best Time to Buy and Sell Stock
Intitution
To maximize profit, we want to buy at the lowest price and sell at the highest price after buying. So, while iterating through the array, we keep track of the minimum price seen so far, and at each step, calculate the profit if we sell at the current price. The answer will be the maximum of all such profits.
Complxity
Space Complexity
Time Complexity
Code
Last updated