medium1-D Dynamic ProgrammingMicrosoftFacebook
Longest Ascending Trail
A biologist finds the longest run of ever-increasing specimen weights in a chronological log.
Given an integer array, return the length of the longest strictly increasing subsequence.
Choose approach
1
0?
1?
2?
3?
4?
5?
6?
7ipos
1/9
Narrationstep 1 of 9
x=10 → append at tails[0]. tails = [10] (len 1).
Variables
i=0
x=10
pos=0
tailsLen=1
How to think about it
- O(n log n) solution uses patience sorting with binary search over tails.
- Final answer = max dp[i].
Edge cases to catch in interview
- All descending -> 1.
- Single element -> 1.
Examples
Example 1
4{"nums":[0,1,0,3,2,3]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed