Data Structures & AlgorithmsVery hardGATE CS · DSA

What is the maximum product of a non-empty contiguous subarray of [−2, 4, 3, −1, −2, −3, −2, 0]? (Track both the maximum and the minimum product ending at each index.)

  1. A. 4
  2. B. 144
  3. C. 12
  4. D. 145

Correct answer: B. 144

A negative number turns the smallest product into the largest, so keep (max, min) ending at each position and reset across zeros. The answer is 144; tracking only the running maximum gives 12.

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

Exams that ask this topic