16. Best Time to Buy and Sell Stock

prices[i] is a stock price on day i. Choose one day to buy and a later day to sell. Return the maximum profit, or 0 if no profit is possible.

Example 1

Input: prices = [8,2,6,1,4]
Output: 4
Explanation: Buy at 2, sell at 6.

Example 2

Input: prices = [9,7,4,1]
Output: 0
Explanation: Prices only fall, so do not trade.
Hint 1

For each day as the selling day, the best buy is the minimum price before it.

ArraySliding Window