Data Structures & AlgorithmsHardLeetCode-style · TCS NQT

Daily prices are [1, 2, 3, 0, 2, 5, 1, 6]. You may buy or sell one share per day, hold at most one share, and after SELLING you must wait one full day before buying again. What is the maximum profit?

  1. A. 8
  2. B. 12
  3. C. 6
  4. D. 9

Correct answer: A. 8

Keep three states per day: holding a share, just sold (cooldown next day), and free to buy. The cooldown rules out the plain 'sum of rises' answer, and the three-state DP handles it exactly.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic