12. Best Day to Trade
easyarraygreedy
prices[i] is a stock's price on day i. You may buy once and sell once on a later day. Return the maximum profit, or 0 if no profit is possible.
Example 1
Inputprices = [7,1,5,3,6,4]
Output5
Example 2
Inputprices = [7,6,4,3,1]
Output0
Constraints
- 1 ≤ prices.length ≤ 10⁵
- 0 ≤ prices[i] ≤ 10⁴