FreeCareerPath
Build the PrimitiveMedium

Longest Increasing Subsequence

Write `length_of_lis(nums)` returning the length of the longest strictly increasing subsequence. Elements need not be contiguous. length_of_lis([10,9,2,5,3,7,101,18]) -> 4 (2,3,7,101) The O(n^2) DP is a fine first answer. The O(n log n) version keeps an array where position i holds the smallest possible tail of an increasing subsequence of length i+1, and binary searches for where each value belongs. That array is not itself a valid subsequence — only its length is meaningful.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Longest Increasing Subsequence" are saved to your account — logging in takes a few seconds.