You're given an array prices where prices[i] is the price of a stock on day i. You want to maximize profit by buying on one day and selling on a later day.
With prices = [7, 1, 5, 3, 6, 4], the answer is 5. Buy on day 2 (price 1) and sell on day 5 (price 6) for profit 6 - 1 = 5.
You can only hold one share at a time, and you must buy before you sell. What's the maximum profit you can achieve?
Constraints: , prices from to .