Given an integer array nums, return the largest product of any non-empty contiguous subarray of nums.
A subarray's product is the product of all of its elements; a subarray of length one has that element as its product.
The input is generated so that the product of every subarray of nums fits in a signed 32-bit integer.
Examples
Example 1
Input: nums = [2,3,-2,4]
Output: 6
Explanation: The subarray [2,3] has the product 6; no subarray has a larger product (extending across -2 makes the product negative).
Example 2
Input: nums = [-2,0,-1]
Output: 0
Explanation: Every subarray containing only -2 or only -1 has a negative product, and any subarray containing both also contains the 0. The best product is 0.
Constraints
1≤nums.length≤2⋅104
−10≤nums[i]≤10
The product of every subarray of nums is guaranteed to fit in a signed 32-bit integer.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up