positive
and negative
, to keep track of the lengths of the longest subarrays with positive and negative products, respectively.ans
to store the maximum length of a subarray with a positive product.positive
and negative
to zero.positive
and increment negative
if it is not zero.positive
and negative
and increment them accordingly.ans
with the maximum value between ans
and positive
.ans
as the result.