874. Maximum Length of Subarray with Positive Product
0
Medium
Given an array of integers nums, determine the maximum length of a subarray where the product of all its elements is positive. A subarray is a contiguous sequence of zero or more values taken from the array. Return the maximum length of a subarray with a positive product. Note that the product value cannot be zero.
Input Format
The first line contains a single integer N, representing the length of the array. The second line contains N space-separated integers, the elements of the array.
Output Format
An integer denoting the maximum length of a subarray with a positive product.
Example
Input
5
0 1 -2 -3 -9
Output
3
Constraints
1 <= N < 10^5
-10^5 <= nums[i] <= 10^5
Loading...
View Submissions
Console