Longest Increasing Subsequence
Given an integer array nums, return the length of the longest strictly increasing subsequence.
A subsequence is a sequence that can be formed by deleting some or none of the elements of the array without changing the order of the remaining elements.
Example 1
Input
n = 8 nums = [10, 9, 2, 5, 3, 7, 101, 18]
Output
4
Explanation
One longest increasing subsequence is:
[2, 3, 7, 101]
Its length is 4.
Example 2
Input
n = 6 nums = [0, 1, 0, 3, 2, 3]
Output
4
Explanation
One longest increasing subsequence is:
[0, 1, 2, 3]
Its length is 4.
Constraints
Hints:
Hint 1
Let dp[i] represent the length of the longest increasing subsequence ending at index i.
Hint 2
For every previous index j:
if nums[j] < nums[i]
dp[i] = max(dp[i], dp[j] + 1)
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 23, 2026
Last updated
Aug 23, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output