← ALL NOTES
Array

121. Best Time to Buy and Sell Stock

For a sale on day i, the best profit is prices[i] minus the cheapest price on any earlier day — so all you need to track is the running minimum from the left. One pass: keep minPrice (lowest seen so…

Loading…