Loading...
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.
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).
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.
nums.length ≤2⋅104nums[i] ≤10nums is guaranteed to fit in a signed 32-bit integer.Click "Run" to test with sample cases or "Submit" to run all tests.