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

Sign in to watch this lesson
Algorithms - Dynamic Programming · 4:40
Given a sequence of prices, find the longest subsequence that rises strictly. We start with the natural O(n^2) DP over the best length ending at each position, whose back-arrows trace both answers of the example, then switch to the tails array, which stays sorted so lower_bound updates exactly one slot per price in O(log n). The tails are not the answer, so we restore a real subsequence from the slot each price landed in, and measure both methods on this Mac.