Given a list of integers, find the contiguous subarray that has the largest product and return that product. The list will contain at least one integer when not null. Return null for null or empty input.
Example 1:
Input: nums = [2, 3, -2, 4]
Output: 6
Explanation: Subarray [2, 3] has the largest product of 6.
Example 2:
Input: nums = [-2, 0, -1]
Output: 0
Explanation: The subarray [0] gives the maximum product of 0.
Example 3:
Input: nums = [-2, 3, -4]
Output: 24
Explanation: The full subarray [-2, 3, -4] gives a product of 24.
Example 4:
Input: nums = [-2]
Output: -2
Explanation: With only one element, that element is the maximum product.
Example 5:
Input: nums = null
Output: null
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.