Data Structures & AlgorithmsVery hardGATE CS · DSA

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

  1. A. 108
  2. B. 4
  3. C. 432
  4. D. 433

Correct answer: C. 432

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 432; tracking only the running maximum gives 108.

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

Exams that ask this topic