Longest rising streak hidden inside a price series
Asked at Jane Street, Two Sigma
You have a list of daily closing prices. You want the length of the longest strictly increasing subsequence, a set of days (not necessarily consecutive) whose prices keep rising. This is a rough proxy for "how long could a patient trend-follower have kept adding on strength."
prices = [4, 2, 6, 3, 7, 5, 8]
-> 4 # e.g. 2, 3, 5, 8 (or 2, 6, 7, 8)
Return the length of the longest strictly increasing subsequence in O(n log n) time. The obvious pairwise dynamic program is O(n^2); the faster version keeps a clever running structure.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.