Coding Challenge

Maximum Product Subarray

Medium
arraydynamic-programming

Find the contiguous subarray with the maximum product.

Return the largest product of any non-empty contiguous subarray. Negative numbers can flip the best and worst products.

Examples

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

Output: 6

Constraints

  • 1 <= nums.length

Preparing your coding workspace...