Loading
Loading
A fitness tracker records a training score after every session. A coach wants the longest run of sessions, not necessarily consecutive, in which every chosen score is strictly higher than the one chosen before it.
Given the scores in session order, return the length of the longest strictly increasing subsequence. Equal scores do not count as rising.
readings = [5, 2, 8, 6, 3, 6, 9, 7]5 → tails [5]best ending for length 12 → tails [2]2 is a lower start than 58 → tails [2, 8]extends the longest6 → [2, 6], 3 → [2, 3]lower tails for length 26 → [2, 3, 6], 9 → [2, 3, 6, 9]length 47 → [2, 3, 6, 7]length stays 4: 2, 3, 6, 74Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n log n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
For example 2, 3, 6, 7 or 2, 3, 6, 9.
Example 2
Equal scores are not rising, so any single score is the best run.