Data Structures & AlgorithmsHardGATE CS · TCS NQT

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

  1. A. 49
  2. B. 48
  3. C. 4
  4. D. 24

Correct answer: B. 48

Track both the running maximum and minimum product, because a negative value can turn the minimum into a maximum. A single running maximum misses cases where two negatives later make a large product from a previously minimal product.

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

Exams that ask this topic