Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Product Subarray
Bookmark
Brute Force
DP (Min & Max)
Prefix-Suffix
Input
Classic
Negative Pairs
Two Negatives
With Zero
Custom
nums
=
[2, 3, -2, 4]
0
1
2
3
2
3
-2
4
0
1
2
3
2
3
-2
4
product =
2
best =
2
0
1
2
3
2
3
-2
4
j
i
[0..0] product =
2
≤ best 2
product =
6
best =
6
0
1
2
3
2
3
-2
4
j
i
[0..1] product =
6
new best
product =
-48
best =
6
0
1
2
3
2
3
-2
4
j
i
[0..3] product =
(-48)
≤ best 6
product =
3
best =
6
0
1
2
3
2
3
-2
4
j
i
[1..1] product =
3
≤ best 6
product =
-6
best =
6
0
1
2
3
2
3
-2
4
j
i
[1..2] product =
(-6)
≤ best 6
product =
-24
best =
6
0
1
2
3
2
3
-2
4
j
i
[1..3] product =
(-24)
≤ best 6
product =
-8
best =
6
0
1
2
3
2
3
-2
4
j
i
[2..3] product =
(-8)
≤ best 6
product =
4
best =
6
0
1
2
3
2
3
-2
4
j
i
[3..3] product =
4
≤ best 6
product =
-
best =
6
0
1
2
3
2
3
-2
4
Max product =
6
algo
master
.
io
Step:
Try every subarray: fix a start, extend the end, and track the running product.
0 / 11
Input
Classic
Negative Pairs
Two Negatives
With Zero
Custom
nums
=
[2, 3, -2, 4]
0 / 11
algo
master
.
io
Step:
Try every subarray: fix a start, extend the end, and track the running product.