Easy · Sliding window
Best Time to Buy and Sell Stock
You are given a list, prices, where each number is the price on one day, in order. Choose one day to buy and a later day to sell. Return the largest profit you can make.
- You must buy before you sell.
- One purchase and one sale only.
- If no sale makes a profit, return 0.
prices = [7, 1, 5, 3, 6, 4] → 5 (buy at 1, sell at 6)Record your take