Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 52s1 days 16 hours 1 minutes 52 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 52s1 days 16 hours 1 minutes 52 seconds.

Sign in to watch this lesson
Algorithms - Arrays · 5:04
The best run of consecutive days in a PnL series, found in one pass. We draw the prefix sums of [-2, 1, -3, 4, -1, 2, 1, -5, 4] as a line, track its lowest point so far and read the answer, 6, as the biggest rise; then run Kadane's algorithm, watch its running sum reset twice, and see why it is the same idea in disguise, measured against checking every segment. We finish with the traps (all-negative arrays, overflow, circular sessions, best trade) and the maximum average over runs of at least L days via binary search on the answer.