awelgorithms

Best Time to Buy and Sell Stock: the skills you need first

Updated

LeetCode · easy · arrays. Track the cheapest buy behind you. Profit is price minus that min.

open on LeetCode

Skills this problem builds on

Stuck on Best Time to Buy and Sell Stock? It is usually one of these. Get each one solid and the solution stops being a trick.

  1. Keep best-so-far
  2. Maintain running min/max
  3. Compare with historical state
check which ones you have 10 minutes, free, no account.

More arrays problems