Dsa
Sliding Window
Easy
Maximum Product Subarray Length
You are given an array of integers where each integer can be positive, negative, or zero. Your task is to find the length of the longest contiguous subarray whose product is positive.
Your program should read an integer array from standard input and print the length of this maximum product subarray.
**Input Format:**
The first line contains an integer n (1 ≤ n ≤ 10^5), the size of the array.
The second line contains n space-separated integers representing the array elements.
**Output Format:**
An integer representing the maximum length of contiguous subarray with a positive product.
**Example:**
Input:
8
1 -2 -3 4 0 -1 2 3
Output:
4
The longest positive product subarray is [4], having a length of 1; however, [-2, -3, 4] has a product of 24, and a length of 3, thus the result is 4.
Key concepts
sliding_windowarraymultiplication
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now