Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the length of the longest contiguous subarray of [2, -3, 0, -1, 4, -2, 5, -1] whose product is strictly positive?

  1. A. 5
  2. B. 4
  3. C. 3
  4. D. 6

Correct answer: B. 4

Track the longest window since the last zero where the count of negatives is even, using the parity of negatives and the positions of zeros. Allowing an odd number of negatives, or ignoring zeros, changes the answer.

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

Exams that ask this topic