java.lang.Object
g1501_1600.s1567_maximum_length_of_subarray_with_positive_product.Solution

public class Solution extends Object
1567 - Maximum Length of Subarray With Positive Product.<p>Medium</p> <p>Given an array of integers <code>nums</code>, find the maximum length of a subarray where the product of all its elements is positive.</p> <p>A subarray of an array is a consecutive sequence of zero or more values taken out of that array.</p> <p>Return <em>the maximum length of a subarray with positive product</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,-2,-3,4]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The array nums already has a positive product of 24.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,1,-2,-3,-4]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The longest subarray with positive product is [1,-2,-3] which has a product of 6. Notice that we cannot include 0 in the subarray since that&rsquo;ll make the product 0 which is not positive.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [-1,-2,-3,0,1]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The longest subarray with positive product is [-1,-2] or [-2,-3].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • getMaxLen

      public int getMaxLen(int[] nums)