Data Structures & AlgorithmsHardFlipkart/Uber OA · placement

Daily prices are [26, 31, 28, 30, 24, 30, 18, 37, 13]. What is the maximum profit with at most ONE buy and one later sell, and with UNLIMITED non-overlapping transactions?

  1. A. 32 and 32
  2. B. 24 and 32
  3. C. 19 and 19
  4. D. 19 and 32

Correct answer: D. 19 and 32

One transaction: track the minimum price so far and the best difference (19) — max − min fails when the minimum comes after the maximum. Unlimited: add every positive day-to-day rise (32).

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

Exams that ask this topic