Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

What is the maximum product of a non-empty contiguous subarray of [-2, 3, -4, 0, -1, 5, -3, -2]?

  1. A. 6
  2. B. 24
  3. C. 0
  4. D. 30

Correct answer: D. 30

Keep both the largest and the smallest product ending at each index, because a negative times a negative can become the new maximum. Tracking only the maximum misses that case, and a zero resets both values.

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

Exams that ask this topic