PythonStudio
Interview Problems

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 compiler