Longest Increasing Subsequence

medium · dynamic programming

Return the length of the longest strictly increasing subsequence of integer nums. A subsequence preserves input order but may skip elements. Equal values do not extend it. Empty input returns 0. At most 300 numbers; either quadratic DP or a tails/binary-search approach is acceptable. Examples (JSON; null means Python None): Input: {"nums": [10, 9, 2, 5, 3, 7, 101, 18]} Output: 4 Input: {"nums": [2, 2, 2]} Output: 1

Starter code

def lis_length(nums: list[int]) -> int:
    """Find the longest strictly increasing subsequence length."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. The GraderCharacter joke · No posting date

    Edge case? Never met her.

  2. InterviewerCharacter joke · No posting date

    Walk me through your thinking. No, not out loud. In code. In silence. While I watch.

  3. Me at 2amCharacter joke · No posting date

    My code works. I have no idea why. I am afraid to touch it. I am going to bed.