Maximum Product Subarray
Given an integer array nums, find the contiguous non-empty subarray with the largest product and return that product. The answer fits in a 32-bit integer.
Open official problem prompt ↗Find the single largest product achievable by any contiguous run of numbers.
Tracking your best and worst account balances as you walk a street of multipliers: a sudden negative can turn your deepest loss into your biggest gain.
- Input
- nums = [2, 3, -2, 4]
- Output
- 6
- Why
- The subarray [2, 3] has product 6, the largest over all contiguous subarrays.
1 <= nums.length <= 2 * 10^4-10 <= nums[i] <= 10The product of any subarray is guaranteed to fit in a 32-bit integer