Grokking Amazon Coding Interview
Ask Author
Back to course home

0% completed

Solution: Maximum Length of Subarray With Positive Product
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an integer array nums, find the maximum length of a subarray where the product of all its elements is greater than 0.

A subarray is a sequence of consecutive elements from the original array.

Examples

  • Example 1:

    • Input: nums = [1, -2, 3, 4]
    • Expected Output: 2
    • Justification: The longest subarray with a positive product is [3, 4], with a length of 2.
  • Example 2:

    • Input: nums = [-1, -2, -3, -4]
    • Expected Output: 4

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible