Longest Increasing Subsequence Problem

Longest Increasing Subsequence Problem — ExecCode Medium DSA Practice

Solve the Longest Increasing Subsequence problem on ExecCode. Free online medium DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an integer array nums, return the length of the longest strictly increasing subsequence. A subsequence keeps relative order from the original array but does not need to be contiguous. Strictly increasing means each chosen value is greater than the previous chosen value. Return only the length, not the subsequence itself.

Examples

Input nums = [10, 9, 2, 5, 3, 7, 101, 18]; Output 4. Input nums = [0, 1, 0, 3, 2, 3]; Output 4. Input nums = [7, 7, 7, 7, 7, 7, 7]; Output 1

Constraints

1 ≤ nums.length ≤ 2500 -10⁴ ≤ nums[i] ≤ 10⁴

Practice Longest Increasing Subsequence free on ExecCode. Browse DSA problems, topic map, and placement guides.