medium1-D Dynamic ProgrammingLinkedIn
Max Product Streaker
A trader finds the contiguous day streak with the highest cumulative multiplicative return.
Given an integer array, find the contiguous subarray with the largest product.
Choose approach
2
03
1-2
24
3i
1/4
Narrationstep 1 of 4
Init: maxP = minP = best = 2.
Variables
maxP=2
minP=2
best=2
How to think about it
- A negative × min = positive-max candidate.
- Reset to x alone when the chain shrinks the product.
Edge cases to catch in interview
- Zero in the array breaks chains.
- All negatives: even count of negs wins.
Examples
Example 1
0{"nums":[-2,0,-1]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed