#K92177. Longest Subarray with Positive Product
Longest Subarray with Positive Product
Longest Subarray with Positive Product
You are given an array of integers. Your task is to determine the length of the longest contiguous subarray whose product is positive. In other words, find the maximum length of a segment of the array where the product of all numbers is greater than 0.
Note that a subarray is a contiguous part of the array. If no such subarray exists, print 0.
For example, consider the array [1, -2, -3, 4]. The longest subarray with a positive product is the entire array, so the answer is 4.
Edge cases include arrays containing zeros, negative numbers and even an empty array.
inputFormat
The input is read from standard input (stdin). The first line contains an integer n, the number of elements in the array. The second line contains n space-separated integers representing the array elements.
outputFormat
Print a single integer to standard output (stdout) representing the length of the longest contiguous subarray with a positive product.
## sample4
1 -2 -3 4
4