Problem
You get an integer array nums. Find the non-empty subarray that has the largest product, and return that product.
A subarray is a part of the array with consecutive items. The product of a subarray is the result when you multiply all its items.
The answer fits in a 32-bit integer.
Example 1
- Input:
- nums = [3,-1,4,2]
- Output:
- 8
- Explanation:
- The subarray
[4, 2]has the product 8.
Example 2
- Input:
- nums = [-2,5,-3]
- Output:
- 30
- Explanation:
- The product of two negative numbers is positive. So the full array gives the largest product,
-2 * 5 * -3 = 30.
Example 3
- Input:
- nums = [-4,0,-1]
- Output:
- 0
- Explanation:
- Each subarray has a negative product or the product 0.
Constraints
- 1 <= nums.length <= 2 * 10^4
- -10 <= nums[i] <= 10
- The product of each prefix or suffix of nums fits in a 32-bit integer.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Maximum Subarray
Coding · Array · Divide and Conquer · Dynamic Programming
- Maximum Profit in Job Scheduling
Coding · Array · Binary Search · Dynamic Programming
- Maximum Sum of Two Non-Overlapping Subarrays
Coding · Array · Dynamic Programming · Sliding Window
- Partition Array for Maximum Sum
Coding · Array · Dynamic Programming
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
LinkedIn
Leetcode 152. Maximum Product Subarray
Reported Feb 14, 2026 · 7 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 152. Maximum Product Subarray
Reported Nov 17, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
LinkedIn
Maximum Product Subarray
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 72. This is not an interview probability.
View sourceLinkedIn
Maximum Product Subarray