#K62027. Longest Subarray with Positive Product

    ID: 31440 Type: Default 1000ms 256MiB

Longest Subarray with Positive Product

Longest Subarray with Positive Product

You are given an array of integers, \( nums \). A subarray is a contiguous part of an array. Your task is to find the length of the longest subarray for which the product of its elements is positive (i.e. greater than 0). Note that an empty subarray is not considered.

It is guaranteed that \( 1 \leq n \leq 10^5 \), where \( n \) is the length of the array, and each element of the array is an integer. Your solution should be efficient enough to handle large inputs.

Hint: Use a dynamic programming approach or a greedy algorithm to keep track of the length of subarrays with a positive and negative product.

inputFormat

The input is given in two lines:

  1. The first line contains an integer \( n \) representing the number of elements in the array \( nums \).
  2. The second line contains \( n \) space-separated integers which are the elements of the array \( nums \).

outputFormat

Output a single integer which is the length of the longest subarray whose product is positive.

## sample
4
1 -2 -3 4
4

</p>