Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA

Problem: Stock trading allows unlimited transactions, but after selling you must wait one day before buying (cooldown). Prices are [1, 2, 3, 0, 2]. What is the maximum profit?

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

Track three states per day: holding a stock, just sold (cooldown next day), and resting. The cooldown rule forbids buying on the day after a sale, which the state machine enforces.

More Coding Interview Problems questions

Exams that ask this topic