Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Product Subarray

XPChallenge Points: 20
levelLevel: Medium

You are given an integer array nums.
Your task is to find a contiguous subarray within the array that has the maximum product and return that product.
Notes:
• A subarray consists of one or more consecutive elements.
• The product of a single-element subarray is the value of that element itself.
• The result will always fit in a 32-bit signed integer.

Example 1:

Input: nums = [3, -1, 4, -2, 5]

Output: 120

Explanation:

The subarray [3, -1, 4, -2, 5] gives the largest product = 3 × (-1) × 4 × (-2) × 5 = 120.

Example 2:

Input: nums = [-1, -3, -10, 0, 60]

Output: 60

Explanation:

The subarray [60] has the maximum product 60.

Example 3:

Input: nums = [-2, -3, 0, -2, -40]

Output: 80

Explanation:

The subarray [-2, -40] has the product 80

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result